【Timer】定时器使用示例

package cn.itcast.listener;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class SendMailTimer implements ServletContextListener {

@Override
public void contextInitialized(ServletContextEvent sce) {

Calendar c=Calendar.getInstance();
c.set(2017, 2, 20, 16, 3, 0);
Timer timer=new Timer();
timer.schedule(new TimerTask() {

@Override
public void run() {
System.out.println("发邮件!!!");
}
}, c.getTime());
}

@Override
public void contextDestroyed(ServletContextEvent sce) {

}

}

没有更多推荐了,返回首页