Java Reference
In-Depth Information
Listing 7.4. FlyerBean implementation
The FlyerBean in this listing is responsible for scheduling the flyer for delivery and also
sending the email when the timer expires. The TimerService is injected via an annota-
tion . The method getScheduledFlyers has been implemented to drive a web page
enabling someone in marketing to see which flyers have been scheduled for delivery .
The scheduleFlyer method is responsible for scheduling the flyer. The user interface
constructs an instance of ScheduleExpression that will ultimately be passed off to
the TimerService . A TimerConfig instance is created to encapsulate the flyer and
also specify that this timer should survive server restarts . A Timer is created inside the
TimerService using the scheduling from the ScheduleExpression and the con-
figuration from the TimerConfig . Once a Timer is created, information about it
may be retrieved, such as the next time the timer will time out
. The send method is
annotated with @TimeOut
to mark it as the method responsible for executing the task
with the timer completes.
This example is straightforward. The TimerService creates timers that are associated
with the current bean. The method to be invoked when the timer expires can either
Search WWH ::




Custom Search