我有scheduler
:
SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory("quartz.properties");
sched = schedFact.getScheduler();
sched.start();
JobDetail jobDetail;
CronTrigger trigger;
for (ReportDetails report : reports) {
jobDetail = new JobDetail(report.getName() + _REPORT, GRP, ReportJob.class);
jobDetail.getJobDataMap().put(ReportJob.DATA_REPORT, report);
sched.addJob(jobDetail, true);
if (report.getCronExp() != null && report.getCronExp().length() > 0) {
trigger = new CronTrigger(report.getName() + _TRIGGER, GRP);
trigger.setCronExpression(report.getCronExp());
trigger.setJobGroup(GRP);
trigger.setJobName(report.getName() + _REPORT);
sched.scheduleJob(trigger);
}
}
还有我的job
实例:
public class ReportJob implements StatefulJob {
private static final Logger logger = Logger.getLogger(ReportJob.class);
public void execute(JobExecutionContext context) throws JobExecutionException {
ReportDetails report = (ReportDetails) context.getJobDetail().getJobDataMap().get(DATA_REPORT);
report.getLogger().info("job for report started");
...
report.getLogger().info("Job for report ended");
}
}
问题在于,尽管ReportJob实现了StatefulJob,但作业并发运行。
QuartzScheduler_Worker-1 |报告的工作已经开始
QuartzScheduler_Worker-2 |报告的工作已经开始
QuartzScheduler_Worker-2 |报告工作已结束
QuartzScheduler_Worker-1 |报告工作已结束
我希望他们一个接一个地连续运行。如何解决这个问题?
答案 0 :(得分:0)
我理解了我的错误:StatefulJob
阻止具有相同键的作业的多个实例同时运行。虽然我用不同的密钥创建了作业。