Java Reference
In-Depth Information
Chapter 7. Scheduling and timers
This chapter covers
• The basics of the EJB Timer Service
• The basics of cron
• Different types of timers
• Declaring cron timers
• Using ad hoc timers
So far in our study of EJBs, actions performed by beans must be initiated either on startup or
as a result of an external action such as a method invocation from the web tier or to handle
a message delivered via JMS. A user must click something in a web page or a JMS message
must be delivered for an EJB method to be invoked and the application to do something.
While most of the behavior in an application is prompted by user actions, there are times
when you want the application to do something on its own either at a specific interval or at
specific times. For example, you may want the application to send out an email reminder a
day in advance, batch process records at night, or scan a legacy database looking for records
to process every 15 minutes. To implement such behaviors you need the EJB Timer Service.
Using the Timer Service, you can build Enterprise applications that schedule operations.
The EJB Timer Service underwent a major upgrade with the 3.1 release, which added sup-
port for cron-like scheduling. Prior to EJB 3.1, only delayed (performed in 10 minutes) and
interval (executed every 20 minutes) operations were supported. If you were interested in
scheduling operations for specific times or dates, you had to look outside the EJB specific-
ation to third-party solutions. Although these solutions were powerful, they added an extra
layer of unnecessary complexity. Full cron-like scheduling is a core requirement for many
applications, and support should be standardized and available in all containers.
In this chapter we'll delve into how timers can be created both declaratively and program-
matically. We'll also examine how timers interact with transactions and EJB security. But
first, let's explore the basics of scheduling.
Search WWH ::




Custom Search