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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s