• 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

TimerService in JBoss 4.0.5

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

A few questions I couldn't find answers to in freely accessible documents or google:

I have a recurring timer in a JBoss 4.0.5 J2EE application. Once invoked, it executes every few minutes.
The timer works fine. I can invoke it from a servlet when I press a button in a JSP.

I have 2 questions regarding timer services in JBoss:

1. I would like to have the timer start automatically when the container is started without having to do anything manually in the web layer. Is there a way of doing this?

2. Is there a way I can invoke the timer using the jboss jmx-console? Clicking on service=EJBTimerService in the jboss.ejb section in the jmx-console lets me invoke the java.lang.String listTimers() function. This function gives me a list of currently running timers. But how do I invoke a new instance of this timer in the service=EJBTimerService view?
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Carco wrote:
1. I would like to have the timer start automatically when the container is started without having to do anything manually in the web layer. Is there a way of doing this?


If you are talking about EJB timers, then EJB3.1 (which is supported in JBoss AS6) supports "auto timers" which are triggered based on a schedule. The schedule will be read when the bean is deployed and you need not explicitly trigger the timer.

Joe Carco wrote:
2. Is there a way I can invoke the timer using the jboss jmx-console? Clicking on service=EJBTimerService in the jboss.ejb section in the jmx-console lets me invoke the java.lang.String listTimers() function. This function gives me a list of currently running timers. But how do I invoke a new instance of this timer in the service=EJBTimerService view?


Not currently.
 
Joe carco
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply.

Unfortunatley EJB3.1 is not an option. I'm stuck with EJB2.1
So there is no direct "backend" solution? maybe I'll try creating a Servlet that gets launched on startup that invokes the timer ...
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Carco wrote:
So there is no direct "backend" solution? maybe I'll try creating a Servlet that gets launched on startup that invokes the timer ...



Some related discussions:

https://coderanch.com/t/477104/EJB-JEE/java/Java-EE-timer-service-periodical
https://coderanch.com/t/517685/EJB-JEE/java/Deploy-or-application-start-up
 
Greenhorn
Posts: 25
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does it have to be an EJB timer? Perhaps you could use an org.jboss.varia.scheduler.Scheduler MBean (which can be configured to start on container startup), instead. This would also give you a way to invoke the timer from the JMX console (by clicking the "restart schedule" button for the MBean).
 
Joe carco
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sounds great thanks!, I'll give it a try.
 
Joe carco
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jason Cone wrote:Does it have to be an EJB timer? Perhaps you could use an org.jboss.varia.scheduler.Scheduler MBean (which can be configured to start on container startup), instead. This would also give you a way to invoke the timer from the JMX console (by clicking the "restart schedule" button for the MBean).



Works great! Its exactly what I was looking for - thanks!

Only one small problem, the Timer starts before my application is completely deoployed, causing a number of Exceptions to be thrown the first time it executes. My Timer makes calls a session bean which obviously isn't bound when the timer first starts. So I did this in my Timer that implements Schedulable:



I hope theres nothing wrong with that...
 
Jason Cone
Greenhorn
Posts: 25
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm glad it's what you were looking for.

The typical approach for making sure your scheduler doesn't load and execute before another resource it is dependent on is to use a depends-list in the jboss-service.xml configuration (or equivalent annotations, if you're using those, instead). You list the MBean names it is dependent on (you'll probably need to look them up in the JMX Console). Here's an example which lists two EJB dependencies that should be loaded before the Scheduler begins:

 
Joe carco
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jason Cone wrote:I'm glad it's what you were looking for.

The typical approach for making sure your scheduler doesn't load and execute before another resource it is dependent on is to use a depends-list in the jboss-service.xml configuration (or equivalent annotations, if you're using those, instead). You list the MBean names it is dependent on (you'll probably need to look them up in the JMX Console). Here's an example which lists two EJB dependencies that should be loaded before the Scheduler begins:



excellent! thank you very much
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic