简体   繁体   中英

Quartz scheduler - synchronizing jobs

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.

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.

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

JobDetail jobDetail = scheduler.getJobDetail(jobKey);

Refer this Jobs status

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM