Ask the Expert

What are the lifecycle methods for Timer service in EJB 2.1?

What are the lifecycle methods for Timer service in EJB 2.1?

    Requires Free Membership to View

The EJB timer service enables an EJB to be notified when an interval of time has arrived or elapsed. To use the timer service, an EJB must implement the javax.ejb.TimedObject interface, which defines a single callback method, ejbTimeout(). When the scheduled time period is reached, or the interval has elapsed, the EJB container invokes the EJB's ejbTimeout() method, as the following example illustrates:
TimerService timerService = ejbContext.getTimerService();
timerService.createTimer(someMilliseconds, "A test timer");
The lifecycle for a Timer object is as follows:

1) Creation - One of the createTimer methods of the TimerService interface is invoked.

2) Saving - Timers are saved when their container is shut down, when their container crashes, or when their TimerHandle is manually retrieved and saved.

3) Restoring - Timers are restored and become active again when their container is restarted or when their TimerHandle is the getTimer method is invoked.

4) Destroying - Timers are cancelled when the time interval expires, the EJB container cancels the timer (such as when the Timer's EJB instance is removed), or when the cancel method of the Timer is called.

The timer service itself is created by an application server usually during startup. During a graceful shutdown of the application server, the timer service is destroyed which will result in all timers being destroyed and triggers being cancelled.

This was first published in October 2003

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: