我正在尝试创建两个每天都会执行的作业。出于某种原因,只有第一份工作正在执行。没有异常被抛出。知道为什么会这样吗?这是我的代码:
SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
Scheduler sched = schedFact.getScheduler();
sched.start();
JobDetail sysJob = newJob(SysParseJob.class).withIdentity("sysJob").build();
Trigger sysTrigger = newTrigger()
.withIdentity("sysTrigger")
.forJob("sysJob")
.withSchedule(dailyAtHourAndMinute(0, 5)) // execute job daily at 12:05
.build();
sched.scheduleJob(sysJob, sysTrigger);
JobDetail histJob = newJob(HistParseJob.class).withIdentity("histJob").build();
Trigger histTrigger = newTrigger()
.withIdentity("histTrigger")
.forJob("histJob")
.withSchedule(dailyAtHourAndMinute(0, 1)) // execute job daily at 12:01
.build();
sched.scheduleJob(histJob, histTrigger);
答案 0 :(得分:0)
也许您的触发器构建中可能存在一些错误。检查这是否解决了您的目的
public static void main(String[] args) throws SchedulerException,
ParseException {
SchedulerFactory schedFact = new StdSchedulerFactory();
Scheduler sched = schedFact.getScheduler();
sched.start();
JobDetail sysJob = JobBuilder.newJob(HelloJob1.class)
.withIdentity(new JobKey("sysJob")).build();
Trigger sysTrigger = TriggerBuilder
.newTrigger()
.withIdentity(new TriggerKey("sysTrigger"))
.withSchedule(dailyAtHourAndMinute(0, 51))
.startNow()
.build();
sched.scheduleJob(sysJob, sysTrigger);
JobDetail histJob = JobBuilder.newJob(HelloJob2.class)
.withIdentity(new JobKey("histJob ")).build();
Trigger sysTrigger2 = TriggerBuilder
.newTrigger()
.withIdentity(new TriggerKey("sysTrigger2"))
.withSchedule(dailyAtHourAndMinute(0, 52))
.startNow()
.build();
sched.scheduleJob(histJob, sysTrigger2);
}
private static CronScheduleBuilder dailyAtHourAndMinute(int hour,int minute){
return CronScheduleBuilder.dailyAtHourAndMinute(hour, minute);
}