public class EmailSendListener implements ServletContextListener{
@Override
public void contextDestroyed(ServletContextEvent sce) {
// TODO Auto-generated method stub
}
@Override
public void contextInitialized(ServletContextEvent sce) {
//创建一个计时器
Timer timer = new Timer();
//日期对象
Calendar calendar = Calendar.getInstance();
calendar.set(2015, 3, 10, 11, 21, 40);
//schedule 执行任务 时间
timer.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("开始发邮件了--------------------------");
}
}, calendar.getTime());
}
}