users@glassfish.java.net

How to stop properly a timer ??

From: <glassfish_at_javadesktop.org>
Date: Mon, 01 Oct 2007 06:45:41 PDT

Hello everybody

I'm using a cyclic timer (from glassfish timer service) to regulary launch a task into a session bean.

For the initial call of the timer, I'm using a load-on-startup servlet.

My problem is to cancel it when my application is undeployed or the server is shut down (as the timer is persistent, it is run when the server restarts, so each time I restart glassfish I have one more timer that is created, and one more session bean that runs ; furthermore when I do a hot redeploy the timer still runs and as it can't find its session bean anymore and that generates some exceptions...)

So, to stop my timer, I have explored the following ways :

-I have tried to keep a reference on my TimerHandle using jndi. I have tried to stop it using the destroy() method of my servlet, the problem is that I'm not allowed to access the timer from a servlet : bad solution.
-So, there's the idea to use a session bean to cancel it, but we can't be sure that the session bean still exists when the destroy() method of the servlet is run.

One more constraint : it would be nice to have something compliant to the EJB specs.

Thanks for answers !
[Message sent by forum member 'olivier_g' (olivier_g)]

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