Majestic Majestic - 1 year ago 539
Java Question

Unable to store job because one already exists with this identification

I'm new with Quartz.
I succeeded to install it and run it.
But I have an error when I run it for the second time because the job already exists with this identification.

Here my code :

public void scheduleJobs() throws Exception {

try {
int i = 0;

scheduler = new StdSchedulerFactory().getScheduler();

JobKey job1Key = JobKey.jobKey("job"+i, "my-jobs"+i);
JobDetail job1 = JobBuilder

TriggerKey tk1 = TriggerKey.triggerKey("trigger"+i, "my-jobs"+i);
Trigger trigger1 = TriggerBuilder
.withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(11, 25))

scheduler.start(); // start before scheduling jobs
scheduler.scheduleJob(job1, trigger1);


} catch (SchedulerException e) {
LOG.error("Error while creating scheduler", e);

I tried to use an integer i to change the name but it does not work.
Do you have any idea how can I fix it?
Many thanks.

Answer Source

You can:

  • check if the "job key" already exists, and remove the existing job before creating a new one:


  • or create a new job with another key (in your case, each time you execute scheduleJobs(), variable i has the same value (0)

  • or just re-use the same job (why would you create a new job if the old one is still good)

  • or use the RAM Job Store, which does not persist jobs in database (each time you will use your software, you will have an empty job store)

It really depends on what you want to do with your jobs!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download