users@glassfish.java.net

Re: EJB3 timer: automatically start with module deployment?

From: <glassfish_at_javadesktop.org>
Date: Fri, 25 Jan 2008 13:21:54 PST

The easiest way is to create a simple Servlet that has an init method, and in that init method you update or start your EJB timer.

In the web xml file, make sure to flag the servlet to "load on startup".

Then when the WAR starts up, it can initialize the timer in the session bean.

Note also that the time needs only be started ONCE, as in once EVER (sorta).

If you have a simple repeating timer that runs every hour or whatever, ONCE that timer is started, it is PERSISTENT and will REMAIN across server restarts. It has to be specifically canceled. Shutting down and restarting the server doesn't "kill" the timer.

So, when I say you need to start the time only once, I mean only once for the life time of the timer (which can easily transcend the life time of the server).

What this means is that you can't simply have a Servlet start up method that goes out and casually creates a new timer every time the server starts up, otherwise you'll end up with a bunch of timers.

Rather, the servlet should check if the timer exists, and then create it only if it's not there.

Yes, this is one of the nitty, crufty bits that give timers a bad name. A better admin interface to the timers would be very nice. (Note to GF folks -- GF can do this WITHOUT having to wait for EJB 3.1 with changes to the console, thanx!)
[Message sent by forum member 'whartung' (whartung)]

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