Friday, September 13, 2013

How to avoid Spring Quartz job overlap


Quartz 1.x.x

per javadoc "Stateful jobs are not allowed to execute concurrently, which means new triggers that occur before the completion of the execute(JobExecutionContext jobCtx) method will be delayed."

StatefulJob extends Job and it does not add any new methods, to achieve this behavior make the following changes:
From:
public class MySchedulerJob implements org.quartz.Job {
void execute(JobExecutionContext context) {/* method implementation */}
}
To this:
public class MySchedulerJob implements org.quartz.StatefulJob {
void execute(JobExecutionContext context) {/*method implementation*/}
}

Quartz 2.x
Annotations are used in Quartz 2.x, StatefulJob is deprecated.

@DisallowConcurrentExecution
public class MySchedulerJob implements org.quartz.Job {
void execute(JobExecutionContext context) {/*method implementation*/}
}

No comments:

Post a Comment