Managing automatically created EJB persistent timers

Applications or modules use the javax.ejb.Schedule annotation or the schedule element in the XML deployment descriptor to instruct the application server to automatically create EJB timers. An MBean is provided for managing the creation of the automatically created EJB persistent timers.

About this task

The Liberty server creates the EJB automatic persistent timers for an application the first time the application is started within the server process. The timers, and an indication that they have been created, are stored in the database associated with the PersistentExecutor, configured for the EJB timer service. Once created, the automatically created persistent timers for an application will not be created again until an action is taken to specifically clear the indication that they have been created from the database. Even if all of the automatically created timers for an application are removed, the Liberty server will not create any of them again until the indication that they have been created is also removed.

Clearing the indication that the automatically created timers have been created may be done by either manually clearing the timer database or using the EJB timer service MBean. The EJB timer service MBean can be used either programmatically or through a tool such as JConsole. The interface for the EJB timer service MBean is: com.ibm.websphere.ejbcontainer.mbean.EJBPersistentTimerServiceMXBean.

Procedure

  1. Configure the application server to include an EJB feature that supports persistent timers and the rest connector in the server.xml file.
    <featureManager>
         <feature>servlet-3.1</feature>
         <feature>ejbPersistentTimer-3.2</feature>
         <feature>jdbc-4.1</feature>
         <feature>restConnector-1.0</feature>
    </featureManager>
  2. Configure the application server to include a datasource for the EJB timer service in the server.xml file.
    <dataSource id="DefaultDataSource" jdbcDriverRef="DerbyEmbedded">
         <properties.derby.embeddedcreateDatabase="create" databaseName="${server.config.dir}/data/EJBTimerDB"/>
    </dataSource>
    <jdbcDriver id="DerbyEmbedded" libraryRef="DerbyLib"/>
    <library id="DerbyLib">
         <filename="${server.config.dir}/derby/derby.jar"/>
    </library>
  3. Obtain the MBean server connection.
  4. Obtain the EJB persistent timer service MBean.
    import javax.management.MBeanServerConnection;
    import avax.management.ObjectName;
    import com.ibm.websphere.ejbcontainer.mbean.EJBPersistentTimerServiceMXBean;
    ...
    MBeanServerConnection mbsc = <step #3>;
    ObjectName on = new
    ObjectName("WebSphere:feature=ejbPersistentTimer,type=EJBPersistentTimerService,name=EJBPersistentTimerService");
    EJBPersistentTimerServiceMXBean timerServiceMBean =
         JMX.newMXBeanProxy(mbsc, on, EJBPersistentTimerServiceMXBean.class);
  5. Remove the automatically created persistent timers for the application.
    timerServiceMBean.removeAutomaticTimers("<application name>");

    The removeAutomaticTimers() method on the MBean removes both the automatically created timers and the indication that they were created. The next time that the server starts the application, the automatically created persistent timers are created.


Icon that indicates the type of topic Task topic



Timestamp icon Last updated: Saturday, 3 December 2016
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twlp_ejb_perstimer_manage_auto
File name: twlp_ejb_perstimer_manage_auto.html