Java Reference
In-Depth Information
Timer creation
The scheduling of the execution can be done via configuration, programmatically, or by
using annotations. Each approach fulfills a different need. Timers created via configuration
are typically scheduled processes that execute on a fixed schedule. An example would be
a nightly process for deleting temporary files or collecting performance data. Timers cre-
ated programmatically are typically end user-driven and are an integral part of a business
process. For example, an application might enable an administrator to send out an email
broadcast at a specified date and time. This is an ad hoc task—not something an application
should be redeployed for so that an updated configuration file can be reloaded. As you'll
see in this chapter, scheduling is fairly straightforward.
7.1.2. Time-outs
At first glance, a time-out might conjure images of being sent to the corner in grade school
for an infraction. But EJB time-outs bear no relation to elementary school punishments. A
time-out is simply an action, or method, that's invoked when a timer fires. A timer firing
is analogous to an alarm going off—you configure a timer and specify the time-out ac-
tion. The action can be either an implementation of the ejbTimeout method defined in
the javax.ejb.TimedObject interface or a method marked with the @Scheduled
annotation. Time-outs can also be configured via XML configuration files. A time-out is
associated with a timer. We'll go deeper into timers and the implementation details of time-
outs as we go through the rest of the chapter.
Note
A time-out is an action that's performed when the timer operation completes.
7.1.3. Cron
Cron refers to a job scheduler available on many Unix systems including Mac OS X, Linux,
and Solaris, among others. It launches applications or scripts at specific times to perform
common tasks like rotating logs, restarting services, and so on. A configuration file, known
as the crontab , specifies the commands to run along with the scheduling information. Cron
is extremely flexible in its ability to schedule tasks. For example, using cron you could
Search WWH ::




Custom Search