users@glassfish.java.net

Re: How ? Timer Service

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Fri, 12 Sep 2008 13:03:14 -0700

No, you can't rely on an instance variable. It's just a coincidence that the
same instance serves several requests in your test.

Regards,
-marina

glassfish_at_javadesktop.org wrote:
> Is it possible to save the information in form of private variables the way I am doing below?
> (It works for me, as I have tested it, but I have doubts!! since its a Stateless bean...how will the private variables behave!!!)
>
> startScheduler is the variable (boolean) where I store this information.
>
> A. If in first @Timeout the scheduler was paused by ImportService
> B. ImportService will start the scheduler again.
> C. If it was not running, ImportService will not start that.
>
> -----------------------------------------------------------------------------------------------------------------------------------
> @Stateless
> public class ImportServiceBean implements ImportService
> {
> public String getName ()
> {
> return "ImportService";
> }
>
> public void start ()
> {
> try
> {
> for (Object o : timerService.getTimers())
> {
> ((Timer)o).cancel();
> }
> long initDuration = 0;
> long interval = 1000* 10;
> timerService.createTimer(initDuration,interval,null);
> }
> catch (Exception e)
> {
> }
> }
>
> public void startImport (boolean a, boolean b, boolean c,boolean d, Status status, int e)
> {
> this.a = a;
> this.b = b;
> this.c = c;
> this.d = d;
> this.status = status;
> this.e = e;
> this.startScheduler = false;
> start();
> }
>
> public void stop ()
> {
> try
> {
> for (Object o : timerService.getTimers())
> {
> ((Timer)o).cancel();
> }
> }
> catch (Exception e)
> {
> }
> }
>
> public boolean isRunning ()
> {
> return timerService.getTimers().size() > 0;
> }
>
> public Date getNextTimeout ()
> {
> for (Object o : timerService.getTimers())
> {
> return ((Timer)o).getNextTimeout();
> }
> return null;
> }
>
> public long getTimeRemaining ()
> {
> for (Object o : timerService.getTimers())
> {
> return ((Timer)o).getTimeRemaining();
> }
> return -1;
> }
>
> @Timeout
> public void ImportService (Timer timer)
> {
> if(scheduler.isRunning())
> {
> scheduler.stop();
> startScheduler =true;
> }
> else
> {
> if(statusService.getStatus())
> {
> //keep waiting.
> }
> else
> {
> configurationService.readData(a, b, c,d, status, e);
> stop();
> if(startScheduler)
> {
> scheduler.start();
> }
> }
> }
> return;
> }
>
> private boolean a;
> private boolean b;
> private boolean c;
> private boolean d;
> private Status status = Status.DOWN;
> private int e = 1;
> private boolean startScheduler =false;
>
> @Resource
> private TimerService timerService;
>
> @EJB
> private ConfigurationService configurationService;
>
> @EJB
> private Scheduler scheduler;
>
> @EJB
> public StatusService statusService;
> }
> -----------------------------------------------------------------------------------------------------------------------------------
> [Message sent by forum member 'suyogbarve' (suyogbarve)]
>
> http://forums.java.net/jive/thread.jspa?messageID=298971
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>