Reputation: 6003
I am using the following code to create multiple triggers, and then binding all these triggers to one job. But it failed
"org.quartz.ObjectAlreadyExistsException: Unable to store Job : 'Group.Job', because one already exists with this identification.
"
for (SchedulerBean schedulerBean : schedulerList) {
Trigger trigger = newTrigger()
.withIdentity("trigger_" + schedulerBean.getConnectorID())
.usingJobData("ID", schedulerBean.getConnectorID())
.withSchedule(cronSchedule(schedulerBean.crontab))
.forJob(job)
.build();
sched.scheduleJob(job, trigger);
}
sched.start();
Upvotes: 3
Views: 1984
Reputation: 1957
From the error I suspect the sched.scheduleJob(job, trigger);
part tries to schedule the same job multiple times.
Try adding sched.addJob(job, true);
before the for loop to add it only once (the 'true' is for replacing old job if exists), and inside the loop use
sched.scheduleJob(trigger);
instead of sched.scheduleJob(job, trigger);
The sched.scheduleJob(trigger);
is able to add the trigger to the job since you specified it with the .forJob(job)
property
Upvotes: 3