uCosminexus Application Server, EJB Container Functionality Guide

[Contents][Glossary][Index][Back][Next]

2.12.2 Operation during the generation of an EJB timer and execution of a callback

Generate an EJB timer to execute processing at the time specified by the Timer Service. To stop the execution of the processing by the EJB timer, delete the EJB timer. The time for generating and deleting the EJB timer depends upon the type of the EJB timer and upon whether processing is being executed under transaction management. The time for generating and deleting the EJB timer, and the operations of timeout method callback during generation and deletion of the EJB timer are explained below:

During the generation of the EJB timer, a single EJB timer is generated by the timer generation method (createTimer method of the javax.ejb.TimerService object). If an EJB timer is generated, a timeout occurs at the specified time and the timeout method is called back.

Organization of this subsection
(1) Counting of timeout time
(2) Timing of generating the EJB timer and executing callback of the timeout method

(1) Counting of timeout time

During the generation of the EJB timer, in the case of an EJB timer that specifies the time from the invocation of the EJB timer until the execution of the first timeout method, the counting of time starts from the point the method for generating the EJB timer is invoked. The following figure shows the generation of the EJB timer and the start of the time count:

Figure 2-19 Generating EJB timer and starting the time count

[Figure]

(2) Timing of generating the EJB timer and executing callback of the timeout method

The timing of generating an EJB timer and callback of the timeout method depends upon whether the EJB timer is generated under transaction management.

When an EJB timer is generated under transaction management
The EJB timer is generated when a transaction is committed.
The timing of executing callback of the timeout method is different in the case of an EJB timer wherein the time for timeout is reached after the transaction is committed, and in the case of an EJB timer wherein the time for timeout is reached before the transaction is committed. Note that if a transaction rolls back, the generation of the EJB timer is cancelled.
  • In the case of an EJB timer, wherein the time for timeout is reached after the transaction is committed
    The timeout method is called back as per the specified time. The following figure shows the generation of the EJB timer and the execution of callback:

    Figure 2-20 Generating the EJB timer and executing callback (in the case of an EJB timer, wherein the timer for timeout is reached after the transaction is committed)

    [Figure]

    In this figure, the time count is started from the time the method for generating the EJB timer is invoked until the time for a timeout is reached and the timeout method is called back at the specified time. The EJB timer is generated during transaction commit.
  • In the case of an EJB timer, wherein the time for a timeout is reached before the transaction is committed
    The timeout method is called back immediately after the transaction is committed. The following figure shows the generation of the EJB timer and the execution of callback:

    Figure 2-21 Generating the EJB timer and executing callback (in the case of an EJB timer, wherein the timer for timeout is reached before the transaction is committed)

    [Figure]

    In this figure, the time count is started from the time the method for generating the EJB timer is invoked until the time for the timeout is reached before the transaction commits. The EJB timer is not generated until the transaction is committed, therefore, the timeout method is not called back even when the time for the timeout is reached. Callback is executed immediately after the transaction is committed.

When an EJB timer is not generated under transaction management
The EJB timer is generated immediately after the method for generating the EJB timer is invoked.
The following figure shows generation of an EJB timer that is not under transaction management:

Figure 2-22 Generating the EJB timer and executing callback (when an EJB timer is not generated under transaction management)

[Figure]

In this figure, the EJB timer is generated immediately after the method for generating the EJB timer is invoked. After this, the timeout method is called back at the specified time.