I am using quartz framework to add and schedule jobs and triggers. The requirement is to add triggers dynamically for the already existing job in the database. While I am trying to achieve this with below code, I am getting org.quartz.ObjectAlreadyExistsException: Unable to store Job : 'EBP1.AAA', because one already exists with this identification. Job AAA with JobGroup EBP1 is already into the database. I just want to add new trigger for the same job. Kindly help how to achieve this.
String jobName = "AAA";
jobTrigger = jobName + "Trigger"+ (int )(Math.random() * 50 + 1);
String jobGroup = "EBP1";
JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class).withIdentity(jobTrigger, jobGroup).storeDurably()
.build();
if (scheduler.checkExists(JobKey.jobKey(jobName, jobGroup))) {
System.out.println("Job exist");
} else {
System.out.println("New job");
scheduler.addJob(jobDetail, true);
}
CronTrigger trigger1 = (CronTrigger)(newTrigger().withIdentity(jobTrigger, jobGroup).withDescription("default description").forJob(jobDetail)
.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).startAt(futureDate(500, IntervalUnit.MILLISECOND)).build());
scheduler.scheduleJob(jobDetail, trigger1);