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.
The steps to achieve the creation of timers in this fashion include:
- Creating a singleton session bean using the @Startup annotation
- Marking a method with the @PostConstruct annotation
- Creating timers from this method
We will create a singleton EJB and then use the @PostConstruct ...