Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Scheduling EJB's to run at certain times  RSS feed

 
John Fairbairn
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'll be developing EJB components on WebSphere and would like to know if there is any way to schedule EJB's to run at certain times. Is purchasing a product such as Flux the only way to go?
Thanks,
John
 
Craig Demyanovich
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the impression that many appservers have a timer facility built-in, though each is currently specific to the appserver. I believe EJB 2.1will introduce a standard Timer service. Beyond a timer-based approach, though, you would use something like Flux. We're using Kronos, though I was only marginally involved in the decision to purchase it instead of Flux or others.
Good luck,
Craig
 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Craig Demyanovich:
I have the impression that many appservers have a timer facility built-in, though each is currently specific to the appserver.

I'm not aware of such a facility using WebSphere . I know jBoss as a kind of timer but I don't know the details

By the way, that's right, EJB 2.1 will introduce tha timer service thru the TimedObject interface as it is mentioned in chapt 22 of the spec
 
John Fairbairn
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the responses.
I'm not sure if WebSphere supports the new EJB 2.1 specification?
If WebSphere does not support a build-in timer service, I was looking at creating an ordinary java class which extended the TimerTask interface. This object would post a number of messages to a JMS queue. I'd like another object to run automatically when the server starts up (not sure how to configure this). This object would create a new instance of Timer and schedule my TimerTask object.
Does this sound reasonable or a bad idea?
Thanks again.
John
 
Byron Estes
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never really gave this much thought before but you could implement it by creating a MessageDrivenBean (...or something similiar that implements a message listener) that listens to a queue for a mesage "time to run the scheduled thing". In the onMessage() call you could lookup and "run" whatever methods you needed to on you EJB.
You would probably create a single message driven bean that would be a controller for many different possible sceheduled events.
Naturally, we're still missing something. We need something to send out the message to the queue to run the scheduled item.
Another application (...maybe a simple looping application/daemon) would be the keeper of the schedule and tasks. This would push messages to the queue to notify the listener (i.e. messagedrivenbean) to perform a task.
The nice thing about this is that it's asynchronous. If the App Server is up...the message bean will be listening and it will perform the necesary tasks.
If the app Server is down, when it comes up the messages will be waiting and they will be processed at that time.
You could easily add some additional functionality to gather notifications that the task was performed and metadata about when it happended and the outcome. You could "peek" on the queue to see messages that haven't been consumed and generate warning emails to appropriate parties etc...
I'm not familiar with Kronos or Flux, so I don't know their features, how they are implemented or deployed, but I kind of like the idea of separating the scheduler from the task performer and doing with an asynchronus form of communication (messaging).
I'm through rambling now...
 
John Fairbairn
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another application (...maybe a simple looping application/daemon) would be the keeper of the schedule and tasks. This would push messages to the queue to notify the listener (i.e. messagedrivenbean) to perform a task.
The nice thing about this is that it's asynchronous. If the App Server is up...the message bean will be listening and it will perform the necesary tasks.
If the app Server is down, when it comes up the messages will be waiting and they will be processed at that time.

Yeah... I like the idea of decoupling the task from the scheduler and using MDB's. I'm going to try this except I'd like to use Java's built Timer and TimerTask objects instead of building a custom looping application.
When I create my Timer object, I can run the associated thread as a daemon. The TimerTask object runs as a thread and is invoked by the Timer object at regular intervals and could place messages on a JMS queue. The MDB (which executes the task) would pick it up.
The only thing is how to invoke the Timer object automatically when the server starts up... any ideas?
I like rambling too
Thanks again,
John
 
Byron Estes
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Part of the reason I thought it would be better to run the scheduler on some other box, not just out of process was so that it would pretty much always be up. If your OS is NT you can take almost anything and make it a service so that you don't need to have someone logged onto the server. You start it up and the service automatically starts.
If, however, you are determined to run the timer on the same server, many app servers have the capability to auto/first time run servlets and jsps automatically so the first user doesn't need to wait while everything compiles/initializes on the first hit. You could use that capability, if your app server has it, to run a servlet with an init() method that fires up your timer.
Let me know how it goes.
Regards,
 
John Fairbairn
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Byron,
I ended up using a servlet which started up automatically when the web server started up... a little clugey but I needed the process to get triggered. The bad part like you said is that if the app server is down - the scheduler (timer object) is also down. An NT service would have also worked like you said. The boss wasn't too keen on this and wanted it on the app server.... ah well.
Thanks for your advice.
Cheers,
John
 
Byron Estes
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
Nice trading messages with you!
Regards,
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!