当前页面: 开发资料首页 → JSP 专题 → 我设置时间执行程序,为什么老是不按照我设定的时间运行的呢??
我设置时间执行程序,为什么老是不按照我设定的时间运行的呢??
摘要: 我设置时间执行程序,为什么老是不按照我设定的时间运行的呢??
timer = new Timer(true);
Date timeToRun = new Date();
timeToRun.setHours(22);
timer.schedule(new ModifyClientJF(),timeToRun,1000*60*60*24); // 定时1分钟
我想每天晚上10点执行。但是跟踪调式的时候一启动web就开始执行了完全没按照我的设定的时间来这是为什么的呢?哪里设置错了的吗?
楼主,你用错了吧.你参考一下java api
int delay = 1000; //milliseconds
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//...Perform a task...
}
};
new Timer(delay, taskPerformer).start();
我的方法是绝对可以的
自己解决了。