Creating timers upon application deployment

Sometimes it is useful to create a timer as soon as the application is deployed. Many applications have actions that need to occur on a regular basis. Creating timers for these actions at application start up is a convenient way of addressing this need.

One way to achieve this is to use a singleton EJB. Here we will programmatically create a timer that generates a JVM memory report after the application has been deployed.

Getting ready

The steps to achieve the creation of timers in this fashion include:

  1. Creating a singleton session bean using the @Startup annotation
  2. Marking a method with the @PostConstruct annotation
  3. Creating timers from this method

    We will create a singleton EJB and then use the @PostConstruct ...

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.