Java Reference
In-Depth Information
7.1. Scheduling basics
This chapter is concerned with scheduling method invocations on EJB using the EJB Timer
Service. The concept of the Timer Service isn't that different from the timer on your kit-
chen stove. When the timer goes off, you either pull the cookies out of the oven or stir
another ingredient into the pot. Putting this in the context of the container, when a timer is
created by an application—either from configuration files or programmatically—a timer is
set. When the timer goes off, a bean is plucked from the method-ready pool (unless it's a
singleton bean), and the specified method is invoked, as shown in figure 7.1 . In the case of
a singleton bean, the existing singleton instance is used. The method is invoked just as if a
user accessing it from a web interface invoked it. The container will perform dependency
injection, and no special setup or logic is required on your part. If the timer is a reoccurring
timer (every 10 minutes, for example), another timer is set to go off in 10 minutes.
Figure 7.1. Timer Service in a nutshell
In the upcoming sections we'll define time-outs and look at cron functionality, the timer
interface, and finally the different types of timers. This section has quite a bit of material
for you to digest, but all we're really covering is an egg timer on steroids. Let's start by
looking at the core features of the Timer Service.
7.1.1. Timer Service features
Let's now turn our attention and examine the fundamental features of the EJB Timer Ser-
vice. Using the EJB Timer Service, tasks can be scheduled at specific dates and times,
for specific intervals, or after an elapsed duration. Although the Timer Service is robust
and timers will survive server restarts/failures, the Timer Service doesn't support real-time
scheduling. This means that you shouldn't use the EJB scheduling capabilities for situ-
ations where you must respond to real-world events within a measureable timeframe. A
measurable timeframe is a period of time in which you absolutely must process a request or
provide a response. The EJB Timer Service is applicable in situations that aren't mission-
critical (where something bad happens if you're late by a nanosecond). For example, send-
ing out an email broadcast at midnight with bid statuses is a good fit for the Timer Ser-
Search WWH ::

Custom Search