Java Reference
In-Depth Information
point in time, once after an elapsed time, and so on. For example, time-delayed timers could
be used to refresh cached pick lists in a singleton bean every 20 minutes. These timers are
useful but not as flexible or as powerful as the calendar-based timers.
Calendar-based timers are based on the cron scheduling concepts we covered earlier.
With calendar-based timers, complex execution schedules can be constructed. Cron-based
scheduling is very powerful and simplifies support for a wide variety of temporal business
progresses. For example, a data synchronization process can be scheduled to start during
the middle of the night and pause before people arrive in the morning so as to not negat-
ively affect system performance during the workday.
Looking at timers based on whether they're time-delayed or calendar-/cron-based is one
approach to understanding the Timer Service. This approach enables you to compare the
services available prior to EJB 3.1 and afterward. If you're working with an existing EJB 3
system, this puts using external libraries such as Quartz into perspective.
Another approach to decomposing the functionality available with the Timer Service is to
break down timers by how they're created. Timers can be created either declaratively or
programmatically. Declarative timers are built into the application and can be changed only
via configuration, which requires an application restart. Programmatic timers can be cre-
ated at runtime to implement time-based business processes. Let's start by looking at de-
clarative timers.
7.2. Declarative timers
Either placing annotations on bean methods or declaring them in an application config-
uration file creates declarative timers. Timers created programmatically are best used for
routine maintenance tasks or business processes that really don't change. For example, de-
clarative timers are a good fit for recalculating performance of a portfolio every night, or,
in the case of ActionBazaar, downloading the latest UPS tracking information to know
what shipments have been received. Because timer configuration files are container-spe-
cific, we'll focus this section on the @Schedule annotation. This annotation was added
with EJB 3.1 and configures calendar-/cron-based timers. To create time-delayed timers,
you need to use the programmatic API discussed in section 7.3 .
Search WWH ::




Custom Search