concept timer in category ejb

This is an excerpt from Manning's book EJB 3 in Action, Second Edition.
The TimerService API has been enhanced to expand the scope of where and how timers may be retrieved. Prior to EJB 3.2, the Timer and TimerHandler objects could only be accessed by the bean that owned the timer. This restriction has been lifted, and a new API method called getAllTimers() has been added that will return a list of all active timers in the EJB module. This allows any code to view all timers and have the ability to alter them.
In this chapter we’ll delve into how timers can be created both declaratively and programmatically. We’ll also examine how timers interact with transactions and EJB security. But first, let’s explore the basics of scheduling.
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 kitchen 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.
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.