The EJB timer service provides a basic scheduling capability, initiated by stateless session beans or MDBs. An EJB creates a timer by invoking the TimerService.createTimer()
method. The created timer is actually a javax.ejb.Timer
object, which is a notification to the container of a timed event to be scheduled. The scheduled event can be either a fixed point in time or an interval.
The same EJB will have a @Timeout
annotated callback method which is invoked by the container when the scheduled event occurs. This method contains any business process logic. The callback method has the Timer
object as a parameter. There are a number of methods in the javax.ejb.Timer
interface which provide information about the timed event.
We also saw how to cancel timers. We made use of TimerService.getTimers()
method which provides all active timers associated with the current bean.
Finally we looked at timers and transactions.