Fixed Delay Scheduling with Quartz

 

With this (Fixed Delay) kind of scheduling there is always a same fixed delay between termination of one execution and commencement of another, as can be shown in the following image.

fixed-delay-scheduling

Java supports this kind of scheduling inherently through java.util.Timer and java.util.concurrent.ScheduledExecutorService, however achieving fix delay using quartz is not that straight forward (Specially when misfires are considered)

One might consider the easy approach, of rescheduling itself from within the execute method of quartz job.

quartz-schedule

Here is the implementation, you would keep the reschedule method in util class as static method.

quartz-reschedule-from-job

However, a better approach would be to use Quartz listeners:

quartz-reschedule-from-listner

Here is the implementation of the listener

quartz-reschedule-from-listner-code

Here is the usage :

quartz-reschedule-from-listner-usage

Here is the code for FixdedDelayJobData.java and FixedDelayJobListener.java

Advertisements