Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Fixed Delay Scheduling With Quartz

DZone's Guide to

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.

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

With 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.

fixed-delay-scheduling

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.

quartz-schedule

Here is the implementation. You would keep the reschedule method in the util class as a 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.

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.

Topics:
quartz ,java ,scheduling ,fixed delay ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}