Fixed Delay Scheduling With Quartz
In this post we take a look at how to use the Quartz library to implement Fixed Delay Scheduling. Read on for more info and some code.
Join the DZone community and get the full member experience.
Join For FreeWith this (Fixed Delay) kind of scheduling, there is always an identical fixed delay between the termination of one execution and the commencement of another, as can be shown in the following image.
Java supports this kind of scheduling inherently through java.util.Timer and java.util.concurrent.ScheduledExecutorService. However, achieving a fixed delay using Quartz is not that straight forward (especially when misfires are considered).
One might consider the easy approach — rescheduling itself from within the execute method of the Quartz job.
Here is the implementation. You would keep the reschedule method in the util class as a static method.
However, a better approach would be to use Quartz listeners:
Here is the implementation of the listener
Here is the usage:
Here is the code for FixdedDelayJobData.java and FixedDelayJobListener.java.
Published at DZone with permission of Mohammad Nadeem, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments