uCosminexus Application Server, EJB Container Functionality Guide
The Timer Service is functionality for invoking Enterprise Beans at a specified time, elapsed time, or interval. This functionality is provided in the EJB container. If you use the Timer Service, the processing wherein the time is specified, such as batch processing with the time when the machine load is low specified and daily processing at a fixed interval, can be executed easily.
This section explains the contents of the timeout value that can be set in the Timer Service, the operations of the EJB timer used to set timeout, and the operations of the Timer Service.
This subsection explains the timeout value that can be specified in the Timer Service, the support range of the Timer Service, as well as transaction management by the Timer Service.
Use the API defined in Java EE to operate the Timer Service from the Enterprise Bean. Generate an EJB timer to execute a processing for which a time is specified. Specify the time for timeout in the EJB timer. The generated EJB timer is managed in the EJB container and once the time for timeout is reached, the Enterprise Bean method is called back by the EJB container. The method that is called back at this point is called the timeout method.
The following figure shows an overview of the Timer Service processing:
Figure 2-17 Overview of the Timer Service operation
The following two types can be set as the types of EJB timers:
The following table describes the types of timers that can be set as an EJB timer as well as example settings:
Table 2-32 Types of timers that can be set as EJB timer and example settings
Timer type | Example settings | Description |
---|---|---|
single-event | 2006/4/15 12:00 | Execute the timeout method only once at 2006/4/15 12:00. |
After 24 hours | Execute the timeout method only once, after 24 hours from the generation of EJB timer. | |
Interval | 2006/4/1 24 hours interval from 12:00 | Execute the first timeout method at 01.04.06 12:00. After this, repeat the timeout method at an interval of 24 hours. |
10 hours interval after 24 hours | Execute the first timeout method after 24 hours from the generation of EJB timer. After this, repeat the timeout method at an interval of 10 hours. | |
calendar-based | First day of every month 12:00 | Execute the timeout method on the first day of every month at 12:00 |
The following figure shows the operations of the single-event timer and interval timer from among the EJB timers. This figure shows the operations of the single-event timer that calls back the timeout method only once at 2:00 and the interval timer that calls back the timeout method at an interval of two hours, starting from 2:00.
Figure 2-18 Operations of the single-event timer and interval timer
The following table describes the support status of the Timer Service functionality defined in the Java EE specifications:
Table 2-33 Support status of the Timer Service functionality defined in the Java EE specifications
Timer Service functionality defined in the Java EE specifications | Support status |
---|---|
Transaction | Y |
EJB timer persistence | --# |
Acquiring the TimerService objects (DI, JNDI lookup, EJBContext) | Y |
Specifying the timeout method (annotation, TimedObject implementation) | Y |
Specifying the timeout methods (specifying by DD) | -- |
The following table describes the support status of Timer Service functionality for various types of Enterprise Beans:
Table 2-34 Support status of Timer Service functionality for various types of Enterprise Beans
Timer Service functionality | Message-driven Bean | Session Bean | Entity Bean | ||
---|---|---|---|---|---|
Stateful Session Bean | Stateless Session Bean | Singleton Session Bean | |||
Acquiring the TimerService objects | N | -- | Y | Y | N |
Operating the objects related to the Timer Service (TimerService, Timer, TimerHandle) | N | Y | Y | Y | N |
Automatic generation of the timer with annotation | N | -- | Y | Y | N |
The Timer Service supports transactions. Specifically, the generation of an EJB timer, deletion of the EJB timer, and the timeout method comply with the transactions. The transaction management of the timeout method is explained below:
For details on generating the EJB timer, see 2.12.2 Operation during the generation of an EJB timer and execution of a callback, and for details on deleting the EJB timer, see 2.12.4 Deleting the EJB timer.
In the timeout method, you can select either BMT or CMT for transaction management.
If CMT is selected, the transaction attributes that can be specified in the timeout method are as follows:
If an attribute other than those described above is specified, the J2EE applications fail to start.
In the timeout method, when the Required attribute or the RequiresNew attribute is specified in CMT, callback will be retried if the transaction rolls back during callback of the timeout method. For details on retrying callback, see 2.12.5(2) Retrying callback of the timeout method.
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.