How to use EJB Timers in WebSphere

Posted by Marcel Friedmann on 12:53 PM with No comments
WebSphere Application Server supports the scheduler interface of Java EE. Each server process has its own embedded derby database to handle the persistent timers. Persistent timers persist through restarts of the application server.

To use the embedded derby timer database now additional configuration is required.
Just simply deploy your EJB Timer Service to the server process (e.g. server1).

The following source code shows a very simple EJB Timer service which prints out a message every 10 seconds. A wrapping ejb timer example project can be downloaded here.

import javax.ejb.Schedule;
import javax.ejb.Stateless;
 * Stateless Bean which prints out time in milliseconds every 10 seconds
public class TimerService {
    @Schedule(second="*/10", minute="*",hour="*", persistent=true)
    public void doIt(){
        System.out.println("time: " + System.currentTimeMillis());

Setting up an persistent cluster timer requires a WebSphere ND installation - and some additional setup tasks,
If you want to enable persistent
timers in a cluster you need to switch to an external database system like Oracle, DB2 or MqSQL.

First create a JDBC / JNDI Datasource to this external database and then navigate to
Servers > Server Types > WebSphere Application Servers > <server-name> >  EJB timer service settings
and select the newly created datasource as " under "Persistent EJB timer configuration" and "Use internal EJB timer service scheduler instance".

Categories: , ,