Creating and using programmatic timers

Timers can be created using methods of the TimerService interface. This interface supports methods for creating timers which generate events at a specific time, after an elapsed time, after a specific interval, or according to a schedule. This approach provides the client with the ability to initiate a timer.

Getting ready

There are two basic steps needed to create a programmatic timer:

  1. Using a TimerService instance to create the timer, and
  2. Declaring a callback method using the @Timeout annotation

    As we will see, there are several TimerService interface methods available to create a timer. Most of these will be explored in the There's more section of this recipe. Initially, we will use the createSingleActionTimer ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.