public class IndexTimer {
private static Timer timer = new Timer();
public static void start() {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH) + 1;// 下一天
// 定制每天的hour:00:00执行,默认3时
int hour = 2;
calendar.set(year, month, day, hour, 00, 00);
Date date = calendar.getTime();
TimerTask task = new TimerTask() {
public void run() {
try {
SpringContext.getBean(SearchService.class).initIndex();
} catch (DataAccessException e) {
e.printStackTrace();
}
}
};
System.out.println(date + "=============================");
int period = 1000 * 60 * 60 * 24;
timer.schedule(task, date, period);
}
public static void shutdown() {
timer.cancel();
}
}
1 个解决方案
#1
你对首次执行时间有问题还是间隔时间有问题?
把间隔时间缩短到分钟级做测试
把间隔时间缩短到分钟级做测试
#1
你对首次执行时间有问题还是间隔时间有问题?
把间隔时间缩短到分钟级做测试
把间隔时间缩短到分钟级做测试