Timers and schedulers
The timer is an object similar to an alarm because it counts the milliseconds since the moment it is started. With a timer, you can, for example, set a time point so that an operation can be performed when it expires.
The timer can act on any method of an EJB. When a method is marked with the @Timeout
annotation, you are able to work with a timer. The method will automatically start when the configured timeout of the timer expires. Here's a sample of the timeout
method:
@Timeout publicvoid timeout(Timertimer) { ... timeoutDone = true; }
The timer object represented by the javax.ejb.Timer
interface holds the countdown for the start of the method defined in the getTimeRemaining()
method. The timer is configurable at runtime through the TimerConfig
, which we will show in the next section.
Here are some other utilities that you can use with the timer object:
- Next timeout: If the timer is configured as a scheduler, you can see when the timeout starts. The scheduler will be...