Quartz 2.0 for Java
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();
scheduler.start();
// ...
scheduler.shutdown();
} catch (SchedulerException se) {
se.printStackTrace();
}
}
}
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")
.build();
Trigger trigger = newTrigger()
.withIdentity("trigger1", "group1")
.startAt(futureDate(2, IntervalUnit.HOURS))
.withSchedule(repeatHourlyForever())
.modifiedByCalendar("holidays")
.build();
// 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.

