Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Eric Bruno

Dr. Dobb's Bloggers

Quartz 2.0 for Java

April 11, 2011

I recently spoke with Mike Allen of Terracotta about the new release of Quartz for Java developers. In a sentence, Quartz is a open-source job scheduler for Java developers, and can be used to schedule tasks that range from simple to complex; from few to thousands. Although the UNIX CRON utility comes to mind, Quartz differs in some significant ways. First, it's built for Enterprise Java application developers, with a well-thought out API. Second, it's built to scale across many nodes, and works in clustered environments to ensure jobs execute even when nodes fail. Third, it has a built-in rich GUI application to make it easier to schedule jobs, and gain visibility into existing jobs. A sample screenshot is shown here:


In my experience, Quartz can be used to perform the important, but often neglected, tasks such as triggering email messages based on events and other triggers, calculation of key statistics at important points during the day (i.e., in financial applications), as well as log and other file maintenance. Given that an open-source version is offered, it's used in Java applications at about half of the Fortune 500 companies.

Creating a Quartz Java application is as simple as this sample application:

import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;

public class QuartzTest {
    public static void main(String[] args) {
        try {
            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
            // ...

        } catch (SchedulerException se) {

The New Quartz 2.0

Allen described a series of enhancements that have been grouped together for the new 2.0 release of Quartz, which include:

1) Simplification of the API: Terracotta have moved to what they call a "fluent" API, which is a more natural way to program tasks, create triggers, and fire events. Here's an example of how to use the API:

JobDetail job = newJob(SimpleJob.class)
    .withIdentity("job1", "group1")

Trigger trigger = newTrigger()
    .withIdentity("trigger1", "group1")
    .startAt(futureDate(2, IntervalUnit.HOURS))

// Tell quartz to schedule the job using our trigger
scheduler.scheduleJob(job, trigger);

2) Quartz Manager: A new GUI tool to monitor and manage Quartz jobs. In the past, Terracotta found that users created some form of this themselves, and decided to provide a unified admin tool to avoid this. The rich GUI tool (which uses Flash) allows you to view, monitor, and control multiple Quartz servers, across a cluster, and will be packaged with the commercial version only. Additionally, a JMX interface to Quartz has been provided to add programmatic control and monitoring of Quartz tasks outside of the new GUI.

3) Quartz Where: A new software add-on package that helps you control application scalability, by sharing scheduled task loads across multiple scheduler instances. This adds programmer control over how and where work should execute, with flexible constraints. For example, you can group tasks, along with server nodes, and assign tasks to nodes based on criteria such as those with the most available memory, lightest CPU load, most disk space, most CPU cores, specific OS versions, and so on.

Overall, Terracotta has made a big investment in Quartz, and has worked to build it into its overall vision of bringing data closer to the Java application to improve performance and scale. Whereas Ehcache and BigMemory work to cache critical application data as close to the application code as possible, Quartz gives more programmer control over how, when, and where that application is executed.

Migration Path

Existing Quartz users should be aware that the new Quartz 2.0 API is a "breaking change," meaning you'll need to use the new API to take advantage of new features. The older API is still available for existing Quartz users that decide to move to the new release for, say, the Quartz Manager. However, you'll need to move to the "Fluent" API to use the full power and new feature-set of Quartz going forward. See http://terracotta.org/quartz for more details, downloads, samples, and documentation.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.