Over a million developers have joined DZone.

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

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

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.


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.

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

quartz ,java ,scheduling ,fixed delay ,tutorial

Published at DZone with permission of Mohammad Nadeem, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}