users@glassfish.java.net

Re: Scheduled task in a clustered environment?

From: <glassfish_at_javadesktop.org>
Date: Fri, 16 May 2008 08:00:57 PDT

You can include the timer directly within the application by using the EJB Timer Service. A Stateless Session Bean or MDB can programmatically create a periodic timer. The timer is associated with the component itself and is persistent. The container will ensure that each timeout happens on some instance of the bean in the cluster, regardless of whether the exact server instance that created the timer is running or not.

Here's the Java EE 5 tutorial section on timers :

http://java.sun.com/javaee/5/docs/tutorial/doc/bnboy.html

The timer service uses a database to store persistent timer info. This database must be configured in the cluster case. More info on that here :

http://docs.sun.com/app/docs/doc/819-3672/beahw?a=view

There is no automatic timer creation support (that's coming in EJB 3.1 ) , so you'll need to either expose an operation for creating the timer that you call once manually after deployment OR use a web application initialization event to create the timer if it doesn't already exist.
[Message sent by forum member 'ksak' (ksak)]

http://forums.java.net/jive/thread.jspa?messageID=274858