users@glassfish.java.net

Re: How to stop properly a timer ??

From: John_Africa_Brokers <john_at_africabrokers.com>
Date: Mon, 1 Oct 2007 16:45:25 +0200

----- Original Message -----
From: <glassfish_at_javadesktop.org>
To: <users_at_glassfish.dev.java.net>
Sent: Monday, October 01, 2007 3:45 PM
Subject: How to stop properly a timer ??


> 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.

This may help you...
http://java-x.blogspot.com/2007/01/ejb-3-timer-service.html

They put the Timer in a bean.
They instance the timer bean in the servlet.
They create a timer client (servlet listener), to reference and control
timer.

The servlet listener makes sure timer acts in duration of servlet.
Very convoluted but will probably work.


>
> Thanks for answers !
> [Message sent by forum member 'olivier_g' (olivier_g)]
>
> http://forums.java.net/jive/thread.jspa?messageID=237812
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>

Agents for Harbor
http://coolharbor.100free.com/index.htm