Set/configure the EJB Timer Service’s DataSource

ejohansson picture ejohansson · Nov 8, 2012 · Viewed 13.8k times · Source

I'm trying to use the Timer Service in EJB 3.1 in my app.

@Stateless
@LocalBean
public class StatelessTimerSessionBean {

    @Schedule(minute = "*", second = "0", dayOfMonth = "*", month = "*", year = "*", hour = "9-17", dayOfWeek = "Mon-Fri")
    public void myTimer() {
        System.out.println("Timer event: " + new Date());
    }
}

".. set the EJB Timer Service’s Timer DataSource setting to a valid JDBC resource.."

from EJB Timer Service

I cannot figure out how to configure the Timer Datasource correctly?

The error I get when deploying is:

SEVERE: Exception while invoking class org.glassfish.ejb.startup.EjbApplication start method
java.lang.RuntimeException: EJB Timer Service is not available

Running: glassfish-3.1.2.2

Answer

ejohansson picture ejohansson · Nov 8, 2012

1. Example Database Setup

  1. I use MySQL for my database.

  2. Create the table EJB__TIMER__TBL from {GF_HOME}/glassfish/lib/install/databases/ejbtimer_{DB_ENGINE}.sql

DB_ENGINE = e.g MySQL:

CREATE TABLE EJB__TIMER__TBL (
    `CREATIONTIMERAW`      BIGINT        NOT NULL,
    `BLOB`                 BLOB,
    `TIMERID`              VARCHAR(255)  NOT NULL,
    `CONTAINERID`          BIGINT        NOT NULL,
    `OWNERID`              VARCHAR(255)  NULL,
    `STATE`                INTEGER       NOT NULL,
    `PKHASHCODE`           INTEGER       NOT NULL,
    `INTERVALDURATION`     BIGINT        NOT NULL,
    `INITIALEXPIRATIONRAW` BIGINT        NOT NULL,
    `LASTEXPIRATIONRAW`    BIGINT        NOT NULL,
    `SCHEDULE`             VARCHAR(255)  NULL,
    `APPLICATIONID`        BIGINT        NOT NULL,
    CONSTRAINT `PK_EJB__TIMER__TBL` PRIMARY KEY (`TIMERID`)
);

2. Server Configuration

GlassFish Admin Console

  1. Start your GlassFish server admin console: usually http://localhost:4848
  2. On your left navigate to [Configurations] > [server-config] > [EJB Container]
  3. Then click the TAB up top [EJB Timer Service]
  4. Then fill out Timer Datasource: with your JDBC Resource eg. [mysql-pu]. ( Note: Defaults to jdbc/__TimerPool