Developing Enterprise bean (EJB) persistent timer applications

Enterprise Bean persistent timers are created either automatically by the container or programmatically by an application. Both types of persistent timers are stored in tables in the database that is configured for the Enterprise Bean timer service in the server.xml file.

About this task

After the persistent timer is created, it exists in the database until one of the following occurs:

  • The timer is not scheduled for further expirations; for example, after a single-action timer expires and runs successfully.
  • The timer is canceled by the application.
  • The timer is canceled by using the EJB timer service MBean (EJBPersistentTimerServiceMXBean)
  • The timer is manually removed from the database. For example, if the timer service database is cleared or removed.

Also, Enterprise Beans persistent timers are associated with an Enterprise Bean based on the application name, module name, and bean name. If an application is updated and any of these names change, the timer continues to exist in the database, but appears to no longer exist as it no longer expires and runs.

The Enterprise Beans specification declares that automatic timers are created by the container when an application is deployed. For the Liberty, timers are created the first time that an application starts within a server process. During the first application start, the automatically created persistent timers are stored in the persistent timer database along with an indication that the application is deployed. The container does not create the automatic persistent timers again until both the timers and the indication that the application is deployed is removed from the EJB persistent timer database.

Procedure

Enable the EJB persistent timer feature in the server.xml file, as shown in the following example.
<featureManager>
     <feature>ejbPersistentTimer-3.2</feature>
</featureManager>
<featureManager>
     <feature>enterpriseBeansPersistentTimer-4.0</feature>
</featureManager>