uCosminexus Application Server, EJB Container Functionality Guide

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

2.12.6 Operations of the EJB timer and callback

This subsection explains the operations of the EJB timer and callback in the following cases:

Organization of this subsection
(1) When a past time is specified in the EJB timer
(2) When multiple EJB timers have been specified in one Enterprise Bean class
(3) When the previous callback has not finished during timeout
(4) When EJB timer cancellation is invoked from multiple threads
(5) When cancel EJB timer is invoked during execution of callback
(6) When an unconcluded transaction with the EJB timer cancelled, is present during callback

(1) When a past time is specified in the EJB timer

The operations differ according to the types of timers.

(a) In the case of a single-event timer or interval timer

When a past time is specified in the EJB timer, call back the timeout method once immediately after the generation of the EJB timer, in the case of a single-event timer. In the case of an interval timer, call back the timeout method during the timeout that occurs after the generation of the EJB timer. The following figure shows the operations when a past time is specified in the EJB timer:

Figure 2-26 Operation when a past time is specified in the EJB timer

[Figure]

In the case of a single-event timer
When a single-event timer that is set to timeout at 2:00, passes the timeout timing and the timeout occurs at 4:15, a callback to the timeout method is executed once, immediately after the timeout occurs.

In the case of an interval timer
When an interval timer that is set to timeout at an interval of 2 hours starting from 2:00, passes the timeout timing and the timeout occurs at 4:15, the callback to the timeout method is executed at the subsequent timeout timings (the first timeout will be executed at 6:00).
(b) In the case of a calendar-based timer

The operations when you specify a past date and time in a calendar format or specify an invalid value as the date and time (such as 2/31) are as follows:

The message KDJE43211-W is output when you invoke the getNextTimeout method.

(2) When multiple EJB timers have been specified in one Enterprise Bean class

When there are multiple EJB timers for one Enterprise Bean class, the callback processing is executed concurrently if callback of these multiple EJB timers overlap. The callback threads and the Enterprise Bean instances for which processing can be performed concurrently are, however, restricted in certain cases. If such callback threads and instances are not present, wait until the release of the threads and the instances.

(3) When the previous callback has not finished during timeout

Only one callback can be executed at a time in a single EJB timer. Depending upon the processing contents, the processing of the timeout method may sometimes take longer. As a result, in the case of an interval timer, the time of the next timeout elapses during execution of the callback processing and the time of multiple timeouts may elapse until one callback finishes. In such a case, the callback processing that could not be performed as per the timeout time is not executed, but callback processing is executed for the timeout that occurs after the time of completion of the previous callback.

The following figure shows the operations when the previous callback has not finished during current callback:

Figure 2-27 Operations when the previous callback has not finished during current callback

[Figure]

In this figure, the setting is such that timeout occurs at an interval of one minute and the callback processing is executed. When the time for the second and the third timeout elapses during processing of the first callback, the second callback processing will be performed at the next timeout after completion of the first callback processing (that is the scheduled time for the fourth timeout). The callback processing is not performed twice for the timeout that has elapsed the timeout time.

(4) When EJB timer cancellation is invoked from multiple threads

When the EJB timer cancellation method of the same EJB timer is invoked concurrently from multiple threads, cancellation is executed sequentially.

If, however, EJB timer cancellation is executed under the transaction management, it is not possible to verify whether the EJB timer is deleted until the transaction is concluded. As a result, if some other thread cancels the same EJB timer, it results in exclusive waiting.

The following figure shows the operations when cancellation of the same EJB timer is invoked concurrently from multiple threads:

Figure 2-28 Canceling the EJB timer invoked from multiple threads

[Figure]

(5) When cancel EJB timer is invoked during execution of callback

When EJB timer cancellation method is invoked during the execution of callback of the timeout method, the operation is as follows:

(6) When an unconcluded transaction with the EJB timer cancelled, is present during callback

For an unconcluded transaction A in which the EJB timer is cancelled, the callback processing of the timeout method waits exclusively from the time of completion of callback until the transaction A is concluded. Therefore, when the timeout method is under the management of a CMT transaction, the conclusion of the transaction will be in the waiting state until the transaction A is concluded. The following figure shows the flow of processing in such a case:

Figure 2-31 Callback operations when an unconcluded transaction with the EJB timer cancelled

[Figure]