I am sorry if this question is too naive, I am expecting the jobs to be scheduled so that it executes one by one, and not parallely.It is executed only once.

From docs, @DisallowConcurrentExecution is

  • An annotation that marks a {@link Job} class as one that must not have multiple instances executed concurrently (where instance is based-upon a {@link JobDetail} definition - or in other words based upon a {@link JobKey}).

But when I schedule a job with same JobKey, I am getting Failed to schedule a job org.quartz.ObjectAlreadyExistsException

If I generate a different JobKey, it is not heeding to @DisallowConcurrentExecution and the job is getting executed in parallel(as mentioned in docs).

Please suggest how can I achieve this, any pointers would really help!

PS: I do not know the jobs that would be scheduled. So, I need some method to dynamically link up the jobs,if the job is already running.

1 Answers

walen On Best Solutions

Same JobKey = same job.
Different JobKey = different job.

Quartz won't let you use the same JobKey more than once because that'd be two jobs with the same key. Like having two users with the same ID.

What you need to do is schedule different JobTriggers for the same JobKey.

@DisallowConcurrentExecution avoids overlapping executions of the same job. If you use a different JobKey, it's not the same job anymore, so the annotation doesn't have any effect. But for a given JobKey with several JobTriggers, @DisallowConcurrentExecution will keep the triggers from launching a new execution of the job, if the previous one hasn't finished yet.

I suggest having a look at Quartz's documentation to get a deeper understanding of the above concepts.