0
votes

I use Quartz scheduler for executing 10 jobs. All of these jobs have their own trigger. So they are executed asynchronously.

However now I need 2 of these jobs to be executed in more specific way. Lets say that Job1 is executed every even minute and Job2 every odd minute. Now I want Job2 to wait for Job1 to be finished. Example: Job1 starts to execute at 10:02. At 10:03 Job2's trigger is fired. But before Job2 starts to execute, it will look at Job1 if it has finished.

I found annotation @DisallowConcurrentExecution for job class that implements Job interface. I thought that this will do the thing, but then I read that it will only disallow concurrent execution of jobs with the same JobKey(name,group). But I cant have the same JobKey for my jobs. So this annnotation is good for just one job I guess.

Do you have some idea how I can solve my issue? Many thanks.

2
If you need to synchronize job executions, then you may be better of using so-called job chains where you can specify a source job and a list of target jobs to be executed (immediately, after a fixed delay, or at a computed time) when the source job finishes executing. You can completely externalize the job chaining logic from your code and avoid using various synchronizers / barriers in your code etc. I can elaborate and provide more details if you think this solution makes sense in your case. - Jan Moravec

2 Answers

0
votes

You can define a static variable to mark Job1 finished or not. When you create Job2, in your code, you can check the static variable before execute.

0
votes

Check the details of existing running job with this call and take appropriate action..

JobDetail jobDetail = scheduler.getJobDetail(jobKey);

Refer this Jobs status