[Logo] Terracotta Discussion Forums
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
How to ensure only one scheduled job runs at a time  XML
Forum Index -> Quartz
Author Message
asimran

neo

Joined: 04/04/2012 03:25:20
Messages: 3
Offline

hi guys,
plz consider the following scenario :

I have n number of jobs (stateful:@DisallowConcurrentExecution) say j1, j2... jn scheduled with quartz scheduler which are scheduled to run at different times in the day.
I want to make sure that no two jobs (say j1, j2) should run concurrently, instead if j1 is executing, j2 (next scheduled job by scheduler) shd wait for j1 to finish (its kind of a locking mechanism which i want to achieve without disturbing the schedule of jobs) and as soon as j1 finish, j2 should start execution.

one point to note here is that the next job to be scheduled is purely dynamic and solely depends upon the schedule mentioned in the CronExpression. Hence using JobChainingJobListener to schedule the next firing job is not suitable.

Regards,
Asim
jhouse

seraphim
[Avatar]
Joined: 11/06/2009 15:29:56
Messages: 1654
Online

The simplest solution would be to create a scheduler with only 1 worker thread, and put these jobs in that.

With only 1 worker thread, only 1 job can fire at a time.
asimran

neo

Joined: 04/04/2012 03:25:20
Messages: 3
Offline

If possible, could you please provide me the sample code for the above worked thread. Please note that, the jobs to be run are dynamically changing (depends upon the Cron Expression in the trigger), so there is no fixed series of jobs like : j1 < j2 < j3. it could be j3< j2 < j1 or J2 < j1 < j3 anything (depending upon their time of fire).

Regards,
Asim
jhouse

seraphim
[Avatar]
Joined: 11/06/2009 15:29:56
Messages: 1654
Online

In your config properties, set:

Code:
 org.quartz.threadPool.threadCount: 1
 
 
Forum Index -> Quartz
Go to:   
Powered by JForum 2.1.7 © JForum Team