import java.util.Timer;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class SmsListener implements ServletContextListener{
    private Timer timer=null;
    public void contextDestroyed(ServletContextEvent sce) {
        timer.cancel();
    }
    public void contextInitialized(ServletContextEvent sce) {
        timer=new Timer(true);
     //设置任务计划,启动和间隔时间
        timer.schedule(new NoteReplyTask(), 0, 86400000);
    }
}
public class MyTask extends TimerTask {
  public void run() {
    // System.out.println("call at " + (new Date()));
    // TODO 此处添加具体任务代码
  }
}
webXml配置
新闻热点
疑难解答