//时间间隔(一天)
private static final long PERIOD_DAY = 24 * 60 * 60 * 1000;
public void executeTask(){
Timer timer = new Timer();
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);// 每天
// 定制每天的03:30:00执行,
calendar.set(year, month, day, 03, 30, 00);
Date date = calendar.getTime();
if (date.before(new Date())) {
date = this.addDay(date, 1);
}
timer.schedule(new MyTask(), date, PERIOD_DAY);
}
static class MyTask extends java.util.TimerTask {
@Override
public void run() {
System.out.println("----Start execute my task------");
}
}
java 定时器
最新推荐文章于 2021-02-16 19:50:03 发布