The Quartz Job examples that you have seen in this article have all been stateless. This means that for each Job execution, any changes made to the JobDataMap during the Job's execution are not maintained between executions. If you need to ability to add, change, or remove values from the JobDataMap, and have those changes seen by the Job during the next execution, a Quartz Stateful Job will be required.
If you're an experienced EJB developer, I'm sure you're wincing right now because Stateful has taken on a negative connotation. This is primarily due to the scalability issues that "Stateful EJBs" present. Quartz Stateful Jobs are implemented by the org.quartz.StatefulJob interface. The key difference between stateless and stateful Jobs is that Stateful Jobs can have only a single instance of the Job definition executing at a time. So, using our example from Example 3, we could only have one instance of the "ScanFTPJob" Job executing at a time. For most situations, this doesn't present a huge problem. If, however, you have a Job that needs to execute so often, or one that takes a long time to finish, Stateful Quartz Jobs may present a scalability problem for you.
The Quartz framework has a very rich feature set. In fact, there are too many features to really appreciate in just one encounter. The following list will give a taste of some of the other features contained within Quartz that we won't have time to talk about in detail here.
Listeners and Plugins
Everybody likes Listeners and Plugins. Download just about any open source framework today and you'll be sure to find support for both of these concepts.
Quartz Listeners are Java Classes that you create and that will receive callbacks from within the framework when key events take place. For example, when a Job is scheduled or unscheduled, or when a Trigger has ended and will not fire anymore, all can be setup to notify your Listener. The framework includes Listeners for the Scheduler, for Jobs, and for Triggers. You can also configure the Job and Trigger Listeners to be global or specific to a Job and/or Trigger.
Once your concrete Listener is called, you can use this knowledge to perform any logic you want within your Listener class. If, for example, you wanted to send an email each time a Job completes, you could program that into the Job. You could also use a JobListener, which enforces a looser coupling and probably makes for a better design.
Quartz Plugins are new functionalities that can be created and added to the framework without having to modify Quartz source. It's done for those developers who need to extend the Quartz framework but don't have time to submit changes to the development team and wait for a new release. If you're familiar with Struts plugins, then you understand the use of Quartz plugins completely.
Rather than Quartz providing a finite set of extension points that may not serve your needs, you have an almost open-ended extension point through the use of Plugins.
Clustering Quartz Applications
Quartz applications can be clustered, both horizontally and vertically, depending on your needs. Clustering offers the same benefits as any other type of clustering:
Currently, Quartz supports clustering with help from a relational database and one of the JDBC JobStores. In a future version, this constraint will be lifted and clustering will possible with the RAMJobStore and will not require a database.
The Quartz Web Application
One of the needs of Quartz users that usually manifests after a few weeks or months of using the framework is the need to integrate Quartz into a GUI. There are facilities that currently exist in the framework that allow you to initialize and start Quartz using a Java servlet. Once you have access to the Scheduler instance, you can store it in the ServletContext of the web container and manage the scheduling environment through the Scheduler interface.
Fortunately, some Quartz developers have been working on a stand-alone Quartz Web Application that can be used to better manage the Quartz Scheduler environment. This GUI, built on top of several popular open source projects like Struts and Spring, supports great functionality, all wrapped up in a simple interface. A screenshot of that GUI is shown in Figure 1.
Figure 1. The Quartz Web Application allows easier management of the Quartz environment.
Quartz is a project on the move. The development team is definitely not resting on its laurels. Things are already in motion for the next major release of the framework. You can get a taste of the features and design being considered for Quartz 2.0 on OpenSymphony's wiki.
As always, everyday Quartz users are free to add suggestions for features and design ideas so that they can be considered for the core framework.
As you start to use more of the features of the Quartz framework, the User and Developer Forum becomes an extremely useful resource for answering questions and communicating with other Quartz users. The individuals that frequent the forums are always helpful and constructive, and you can also count on James House to share his knowledge and comment on your needs and requirements.
The forum is free and you're not required to have a login to search and view the forum archive. However, once you're comfortable with navigating the forum and need to post a reply to someone, you'll need to sign up for a free account.
Chuck Cavaness is a graduate from Georgia Tech with degrees in computer engineering and computer science. He has built Java-based enterprise systems in the healthcare, banking, and B2B sectors. He is also the author of two O'Reilly books, Programming Jakarta Struts and Jakarta Struts Pocket Reference.
Return to ONJava.com.