Reputation: 21
Working with Java Quartz, I was able to schedule one job. Then I tried something like the following code to be able to add an other job. Now neither seems to trigger at the defined time. What am I doing wrong?
I want to use approach like following, not xml configuration.
scheduler = StdSchedulerFactory.getDefaultScheduler();
JobDetail jobFull = new JobDetail("job1", "group1", IntegrationJobFull.class);
JobDetail jobPartial = new JobDetail("job2", "group1", IntegrationJobPartial.class);
CronTrigger triggerFull = new CronTrigger("trigger1", "group1", "job1", "group1", "0 15 3 * * ?");
CronTrigger triggerPartial = new CronTrigger("trigger2", "group1", "job2", "group1", "* 0,30 * * * ?");
scheduler.addJob(jobFull, false);
scheduler.addJob(jobPartial, false);
scheduler.scheduleJob(triggerFull);
scheduler.scheduleJob(triggerPartial);
scheduler.start();
Upvotes: 2
Views: 4967
Reputation: 1781
The JobDetail
s created above are non-durable, this means that the addJob
method will fail. Use the overloaded scheduleJob
method to associate the job and the trigger.
Remove the addJob
and scheduleJob
calls and replace with:
scheduler.scheduleJob(jobFull, triggerFull);
scheduler.scheduleJob(jobPartial, triggerPartial);
Also *
has been specifed the seconds field for trigger2. This will mean that the job will be triggered every second for the specified minutes. I'm not sure if that was the intention.
The desired cron expression may be:
"0 0,30 * * * ?"
Upvotes: 2