您的問題是配置開始時間。 startTime意味着觸發應該發生的時間。由於日期是舊的,因此調度程序會導致失火,並且默認行爲是調度程序立即重新啓動。
刪除setStartTime,默認行爲是開始時間設置爲當前時間和第一觸發時間將是比賽的開始時間所以這個週四之後的cron觸發。
快速小測試通過我一起驗證:
public class Test {
public static void main(String[] args) throws ParseException, SchedulerException {
String groupName = "group";
String cronExpression = "0 13 13 ? * THUR";
CronTrigger cronTrigger = new CronTrigger("trigger_" + groupName, groupName, cronExpression);
cronTrigger.setStartTime(new Date(0));
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
JobDetail detail = new JobDetail("testJob", groupName, TestJob.class);
scheduler.scheduleJob(detail, cronTrigger);
scheduler.start();
try {
Thread.sleep(50001);
} catch (Exception ignore) {
}
}
public static class TestJob implements Job {
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("TEST");
}
}
}
在拆除setStartTime我打印的消息不會觸發。有了它,觸發了打印信息。
*你的意思是:'0 13 13? * FRI' *? – 2012-04-04 09:15:05
哦,是的,我複製它從錯誤的文件實際上 – Waqas 2012-04-04 09:15:50