The precautions when using the Timer Service are explained below:
When the Timer Service is used, there may be a difference in the time specified in the EJB timer, and the time when the timeout method actually is called back. In such a case, the reasons could be as follows:
Execution of a garbage collection
If a garbage collection is executed in JavaVM at the time specified in the EJB timer, the processing of garbage collection is given priority. The timeout method is called back after the garbage collection finishes, therefore, there may be some variations from the specified time.
Platform or hardware environment
Use the time period of JavaVM in the Timer Service. The time period of JavaVM depends upon the platform or hardware environment. The callback is also executed as per the time period of JavaVM, therefore, there may be some variations from the specified time.
On a machine where a J2EE server is running, if you modify the system time using a software, such as NTP client software, the following operations are performed for the timeout time of the already registered EJB timer:
In the case of a single-event timer
Timeout occurs assuming that the system time before modification is inherited.
In the case of an interval timer
The first timeout occurs assuming that the pre-modification system time is inherited after modification. From the second time onwards, a timeout occurs as per the system time after modification.
In the case of a calendar-based timer or when using the method of specifying the @Schedule annotation
If you set only one callback at a specified date and time, a timeout occurs assuming that the system time before the modification is inherited.
If you set a periodic callback, the first timeout occurs assuming that the pre-modification system time is inherited after modification. From the second time onwards, timeouts occur as per the system time after modification.
The following figure shows examples of the callback timing when the system time is not changed, when the system time is returned, and when the system time is advanced.