我正在使用 quartz 调度程序来安排我的工作。我用过 CronTrigger。但问题是触发器被多次触发。这是我设置 cron 调度程序的代码..
SchedulerFactory schFactory = new StdSchedulerFactory();
Scheduler sched = null;
CronTrigger cronTrigger = null;
try {
sched = schFactory.getScheduler();
JobDetail jobDetail = new JobDetail("job1", "group1",SchedulerPBGC.class);
String cronTimerStr = "* 16 15 * * ? *";
LOG.warn("CRON TRIGGER FORMAT FOR PROCESSING PB GC DATA:"+cronTimerStr);
cronTrigger = new CronTrigger("SchedTrigger", "Group1", cronTimerStr);
sched.scheduleJob(jobDetail, cronTrigger);
sched.start();
LOG.warn("SCHEDULER REGISTERED FOR PROCESSING PB GC DATA : TIME :"+cronTimerStr);
} catch (SchedulerException se) {
LOG.error("SchedulerException Message::"+se.getLocalizedMessage());
}
在这里,我的调度程序执行了 10 次作业......在这里你可以看到日志......
2012-06-20 15:16:50,001 DefaultQuartzScheduler_Worker-1 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION STARTED-----------------------
2012-06-20 15:16:50,001 DefaultQuartzScheduler_Worker-1 WARN test.SchedulerPBGC - The value of NO_OF_BEFORE_DAY_TO_RUN must be less then zero ..to start the scheduler
2012-06-20 15:16:50,001 DefaultQuartzScheduler_Worker-1 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION COMPLETED-----------------------
2012-06-20 15:16:51,001 DefaultQuartzScheduler_Worker-2 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION STARTED-----------------------
2012-06-20 15:16:51,001 DefaultQuartzScheduler_Worker-2 WARN test.SchedulerPBGC - The value of NO_OF_BEFORE_DAY_TO_RUN must be less then zero ..to start the scheduler
2012-06-20 15:16:51,001 DefaultQuartzScheduler_Worker-2 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION COMPLETED-----------------------
2012-06-20 15:16:52,001 DefaultQuartzScheduler_Worker-3 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION STARTED-----------------------
2012-06-20 15:16:52,001 DefaultQuartzScheduler_Worker-3 WARN test.SchedulerPBGC - The value of NO_OF_BEFORE_DAY_TO_RUN must be less then zero ..to start the scheduler
2012-06-20 15:16:52,001 DefaultQuartzScheduler_Worker-3 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION COMPLETED-----------------------
2012-06-20 15:16:53,001 DefaultQuartzScheduler_Worker-4 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION STARTED-----------------------
2012-06-20 15:16:53,001 DefaultQuartzScheduler_Worker-4 WARN test.SchedulerPBGC - The value of NO_OF_BEFORE_DAY_TO_RUN must be less then zero ..to start the scheduler
2012-06-20 15:16:53,001 DefaultQuartzScheduler_Worker-4 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION COMPLETED-----------------------
2012-06-20 15:16:54,001 DefaultQuartzScheduler_Worker-5 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION STARTED-----------------------
2012-06-20 15:16:54,001 DefaultQuartzScheduler_Worker-5 WARN test.SchedulerPBGC - The value of NO_OF_BEFORE_DAY_TO_RUN must be less then zero ..to start the scheduler
2012-06-20 15:16:54,001 DefaultQuartzScheduler_Worker-5 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION COMPLETED-----------------------
2012-06-20 15:16:55,001 DefaultQuartzScheduler_Worker-6 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION STARTED-----------------------
2012-06-20 15:16:55,001 DefaultQuartzScheduler_Worker-6 WARN test.SchedulerPBGC - The value of NO_OF_BEFORE_DAY_TO_RUN must be less then zero ..to start the scheduler
2012-06-20 15:16:55,001 DefaultQuartzScheduler_Worker-6 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION COMPLETED-----------------------
2012-06-20 15:16:56,001 DefaultQuartzScheduler_Worker-7 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION STARTED-----------------------
2012-06-20 15:16:56,001 DefaultQuartzScheduler_Worker-7 WARN test.SchedulerPBGC - The value of NO_OF_BEFORE_DAY_TO_RUN must be less then zero ..to start the scheduler
2012-06-20 15:16:56,001 DefaultQuartzScheduler_Worker-7 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION COMPLETED-----------------------
2012-06-20 15:16:57,001 DefaultQuartzScheduler_Worker-8 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION STARTED-----------------------
2012-06-20 15:16:57,001 DefaultQuartzScheduler_Worker-8 WARN test.SchedulerPBGC - The value of NO_OF_BEFORE_DAY_TO_RUN must be less then zero ..to start the scheduler
2012-06-20 15:16:57,001 DefaultQuartzScheduler_Worker-8 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION COMPLETED-----------------------
2012-06-20 15:16:58,001 DefaultQuartzScheduler_Worker-9 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION STARTED-----------------------
2012-06-20 15:16:58,001 DefaultQuartzScheduler_Worker-9 WARN test.SchedulerPBGC - The value of NO_OF_BEFORE_DAY_TO_RUN must be less then zero ..to start the scheduler
2012-06-20 15:16:58,001 DefaultQuartzScheduler_Worker-9 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION COMPLETED-----------------------
2012-06-20 15:16:59,001 DefaultQuartzScheduler_Worker-10 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION STARTED-----------------------
2012-06-20 15:16:59,001 DefaultQuartzScheduler_Worker-10 WARN test.SchedulerPBGC - The value of NO_OF_BEFORE_DAY_TO_RUN must be less then zero ..to start the scheduler
2012-06-20 15:16:59,001 DefaultQuartzScheduler_Worker-10 WARN test.SchedulerPBGC - ----------PB GC SCHEDULER EXECUTION COMPLETED--------------------
如何将 CronTimer 迭代器设置为 1 ?或如何停止调度程序多次执行作业。
有什么建议吗?
谢谢,
古詹·沙阿。
请您参考如下方法:
我得到了解决方案..
我使用的 cron 语法是: String cronTimerStr = "* 16 15 * * ? *";
在这里,在 15:16 时间,Quartz 将每秒初始化所有可能的工作线程。因此,假设在一分钟内(@ 16 分 60 秒),它将初始化最多 60 个线程。
我将第二个参数设置为零。
所以新的语法是“0 16 15 * * ? *”。
现在它工作正常。
谢谢,
古詹·沙阿。