Search

21.6. Configuring the EJB3 Timer Service

download PDF

21.6.1. EJB3 Timer Service

The EJB3 Timer Service is a standard Java EE 6 service for scheduling the invocation of the methods from enterprise beans. Stateless session beans, singleton session beans, and message-driven beans can all schedule any of their methods for callback at specified times. Method callback can occur at a specific time, after a duration, at a recurring interval, or on a calendar-based schedule.

21.6.2. Configure the EJB3 Timer Service

The EJB3 Timer Service can be configured via either the Management Console or Management CLI. You can configure the thread pool used for scheduled bean invocation, and either the directory or datasource used to store the Timer Service data. You might change the default Timer Service directory if faster storage is available than the default directory.

Procedure 21.21. Configure the EJB3 Timer Service Thread Pool via the Management Console

Prerequisite

  • The thread pool to be used by the EJB3 Timer Service must already have been created.

  1. Login to the Management Console.
  2. Click on the Configuration tab at the top of the screen. Expand the Container menu and select EJB 3. Select the Services tab, click on Timer Service. Click Edit.
  3. Click on the EJB3 Thread Pool drop-down list and click on the preferred thread pool's name.
  4. Restart the JBoss EAP instance.

Procedure 21.22. Configure the EJB3 Timer Service Thread Pool via the Management CLI

Note

Add the prefix /profile=PROFILE_NAME to the command for a managed domain.
  1. Run the following Management CLI command.
    /subsystem=ejb3/service=timer-service:write-attribute(name=thread-pool-name,value="thread-pool-name")
  2. Restart the JBoss EAP instance.

Procedure 21.23. Configure the EJB3 Timer Service Directory via the Management Console

  1. Login to the Management Console.
  2. Click on the Configuration tab at the top of the screen. Expand the Container menu and select EJB 3. Select the Services tab, click on Timer Service. Click Edit.
  3. Enter your desired values into the Path and Relative To fields.
  4. Click Save.
  5. Restart the JBoss EAP instance.

Procedure 21.24. Configure the EJB3 Timer Service Directory via the Management CLI

  1. Depending on which paths you want to change, run one or both of the following Management CLI commands. For either path you can use a system value - for example, ${jboss.server.data.dir}.

    Note

    Add the prefix /profile=PROFILE_NAME to the command for a managed domain.
    /subsystem=ejb3/service=timer-service/file-data-store=default-file-store:write-attribute(name=path,value="path")
    /subsystem=ejb3/service=timer-service/file-data-store=default-file-store:write-attribute(name=relative-to,value="relative-path")
  2. Restart the JBoss EAP instance.

Procedure 21.25. Configure the EJB3 Timer Service to use a Datasource via the Management CLI

From JBoss EAP 6.4 you can configure the EJB3 Timer Service to use a datasource instead of a local directory. There is a minor performance cost to this option but it has the advantage of decreasing risk to timer data in the event of a local storage issue.
Once the EJB3 Timer Service is configured to use a datasource, you then must either configure an EJB deployment to use the datastore or configure it as the default for all deployments. For instructions on how to do so, see the procedure Configure one or all EJB3 Deployments to use the Datasource.
Prerequisite

  • The datasource to be used by the EJB3 Timer Service must already exist and the underlying database must support and be configured for READ_COMMITTED or SERIALIZABLE isolation mode.

Note

Add the prefix /profile=PROFILE_NAME to the command for a managed domain.
  • Run the following Management CLI command.
    • datastore_name - A name of your choice.
    • datasource_name - The name of the datasource to be used for storage.
    • database - either postgresql, mssql, sybase, mysql, oracle, db2, or hsql.
    • partition_name - A name of your choice. This attribute is used to distinguish timers pertaining to a particular server instance if multiple JBoss EAP instances share the same database for storing EJB timers. In this case, every server instance should have its own partition name. If the database is used by only one server instance, you can leave this attribute blank.
    /subsystem=ejb3/service=timer-service/database-data-store=datastore_name:add(datasource-jndi-name='java:/datasource_name', database='database', partition='partition_name')

Procedure 21.26.  Configure one or all EJB3 Deployments to use the Datasource

Either configure an EJB3 deployment to use the Timer Service's datasource or configure it as the default for all deployments.
    • To configure an EJB3 deployment to use the datasource, edit the jboss-ejb3.xml of the deployment so the timer section looks as follows. Replace datastore_name with the name of the datastore.
      [<assembly-descriptor>
        <timer:timer>
          <ejb-name>*</ejb-name>
          <timer:persistence-store-name>datastore_name</timer:persistence-store-name>
        </timer:timer>
      </assembly-descriptor>
    • To configure the datasource as the default for all deployments, run the following Management CLI command, then restart the JBoss EAP instance. Replace datastore_name with the name of the datastore.

      Note

      Add the prefix /profile=PROFILE_NAME to the command for a managed domain.
      [/subsystem=ejb3/service=timer-service:write-attribute(name=default-data-store,value=datastore_name)
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.