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配置