Can I run the same job with a different trigger in quartz?

I am using the following code to create multiple triggers and then bind all of those 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();

      

+3


source to share


1 answer


Due to the error, I suspect that part is sched.scheduleJob(job, trigger);

trying to schedule the same job multiple times.

Try adding sched.addJob(job, true);

before the for loop to add it only once ("true" is used to replace the old job if exists) and inside the loop is used sched.scheduleJob(trigger);

insteadsched.scheduleJob(job, trigger);



sched.scheduleJob(trigger);

can add a trigger to the job since you specified it with the property .forJob(job)

+3


source







All Articles