• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Duplicate Timers in JBOSS

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day,

I have used Quartz with no real problems in Tomcat. Now I am using EJB3 over JBOSS 4.2.2 and it looks straight-forward, however I have run into an issue. I seem to end up with multiple instances of the timer. After I have deployed / restarted several times I end up with my job executing repeatedly. Obviously I am not approaching this correctly as the JBOSS is persisting the timer (which is nice), but I am somehow generating duplicates.

First I am creating my timed job the first time my session bean is initialized. Below is my code:



So far, so good, or so I thought. After multiple redeploys and restarts when working on my code I found that the job was running repeatedly with multiple different timer IDs. Following is the log:


16:25:51,566 INFO [PromisPartSpecBean] scheduledJob(Timer timer=[id=1251501729393,target=[target=jboss.j2ee:service=EJB3,ear=OnPromisPartSpecEAR.ear,jar=OnPromisPartSpec.jar,name=PromisPartSpecBean],remaining=17546,periode=60000,canceled_in_tx]) - end
16:25:51,597 INFO [PromisPartSpecBean] updateFwPlans() - end
16:25:51,597 INFO [PromisPartSpecBean] scheduledJob(Timer timer=[id=1251501729637,target=[target=jboss.j2ee:service=EJB3,ear=OnPromisPartSpecEAR.ear,jar=OnPromisPartSpec.jar,name=PromisPartSpecBean],remaining=34179,periode=60000,canceled_in_tx]) - end
16:25:51,644 INFO [OnFwPartSpecBean] init() - start
16:25:51,644 INFO [OnFwPartSpecBean] init() - end
16:25:51,644 INFO [OnFwPartSpecBean] findFwPlans() - start
16:25:51,644 INFO [FwPartSpecDataDelegate] findFwPlans() - start
16:25:51,644 INFO [PromisPartSpecBean] updateFwPlans() - end
16:25:51,644 INFO [PromisPartSpecBean] scheduledJob(Timer timer=[id=1251501729709,target=[target=jboss.j2ee:service=EJB3,ear=OnPromisPartSpecEAR.ear,jar=OnPromisPartSpec.jar,name=PromisPartSpecBean],remaining=34382,periode=60000,canceled_in_tx]) - end
16:25:51,706 INFO [PromisPartSpecBean] updateFwPlans() - end
16:25:51,722 INFO [PromisPartSpecBean] scheduledJob(Timer timer=[id=1251501729407,target=[target=jboss.j2ee:service=EJB3,ear=OnPromisPartSpecEAR.ear,jar=OnPromisPartSpec.jar,name=PromisPartSpecBean],remaining=33210,periode=60000,canceled_in_tx]) - end
16:25:52,175 INFO [FwPartSpecDataDelegate] findFwPlans() - end
16:25:52,175 INFO [OnFwPartSpecBean] findFwPlans() - end
16:25:52,285 INFO [PromisPartSpecBean] updateFwPlans() - end
16:25:52,285 INFO [PromisPartSpecBean] scheduledJob(Timer timer=[id=1251501729560,target=[target=jboss.j2ee:service=EJB3,ear=OnPromisPartSpecEAR.ear,jar=OnPromisPartSpec.jar,name=PromisPartSpecBean],remaining=-1384392,periode=60000,canceled_in_tx]) - end

I am obviously missing some basic aspect about creating and managing timers. I would sure appreciate a little help here.

Thanks,
Stu
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are starting the timer each time your application starts. Obviously jBoss is persisting your timers (which you know). So basically do you want to turn of timer persistence or you can get a list of all timers, and then check if your timer is already running??
 
Stu Quinn
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ankit,

I would like to retain persistence of the timers within the app serve, so yes what I am looking for is how to query the timer service to determine if my timer already exists. I would then check the persisted timer to see if the interval was the same. If it is the same then I will not create it again. If I had changed the interval I would delete the prior instance of the timer and create it again.

Thank you for taking time to help. Life is good at the ranch.
Stu
 
Ankit Garg
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your bean try using TimerService.getTimers(), that will return a list of timers, then you can check the next timeout of the timers using Timer.getNextTimeout(). I've never tried this but I had read it so should work I think...
 
Stu Quinn
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This was just what I needed. From the JavaDoc:


getTimers()
Get all the active timers associated with this bean.



I had expected the Timer to include the interval, but no such luck. However, when you create the timer you can pass an object so I just passed in the interval in for the 'info' parameter and now I am able check to see if the interval has changed. If so I clear the timer and re-create it, otherwise I take no action. Here is the code.



Lastly, the use of the TimerService is not supported in an @PostConstruct method. It might work some of the time, but may also throw some unexpected errors.

All is well.


 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic