Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constraint two jobs not to run simultaneously in Quartz-Scheduler

Is it possible in Quartz-Scheduler, to define execution constraints about job ?

Indeed, I have two class which implements interface Job : JobA and JobB.

JobA will be scheduled every minute. JobB will be scheduled every hour.

I doesn't want JobA and JobB run simultaneously.

Note : JobA and JobB doesn't do the same things.

Thanks for your answers.

like image 363
Sly33 Avatar asked Oct 07 '22 19:10

Sly33


1 Answers

There is no direct support for that. If it was the same job, you could define it as stateful - such jobs can't run concurrently be definition.

Otherwise you can limit the number of Quartz worker threads to 1, additionally you can define thread priorities to choose which job should run first. Unfortunately this solution won't scale to when more jobs are involved.

Finally you can implement this manually without involving Quartz. I guess you don't want some operation or some resource to be accessed at the same time. Consider locking that method/resource so that both jobs run simultaneously, but one blocks and waits for the other to finish.

like image 106
Tomasz Nurkiewicz Avatar answered Oct 10 '22 08:10

Tomasz Nurkiewicz