How to implement a scheduler?
New to J2EE.
I want a session bean to be called every x seconds. The time when the session bean needs to run is stored in a database. Any ideas how?
The only thought I have so far is to write an external timer program to regularly call the session bean. This however means that my solution isn't very scalable as I'd have to run a copy of this timer on every machine my application server was installed on.
Could I have a 'timer' session bean that gets kicked off and never returns, just waiting for the next timer interval to arrive, and when it does it kicks off a separate session bean to run the task. Can one session kick off an independent session?
Hope this makes sense,
Ian Beaumont
[738 byte] By [
IBeaumont] at [2007-9-26 4:30:24]

Keeping external solutions asside for a moment, I cannot seem to think of a case where you can avoid implementing the external entity that calls your Session bean. This, however, can be done portable and possibly scalable.
* Design a thread of code that manages the queries to the database and the calling of the EJB.
* Wrap that code in a Servlet's init()
* Deploy the Servlet and EJB as an EAR.
* Designate the Servlet as something that must get instantiated at startup.
Of course, there are a few pitfalls in implementing the above; especially bullet #1. However, conceptually, this will work. We are avoiding these pitfalls by simply using an external solution that does the above (possibly not in that way). We are using a scheduler called Flux from www.simscomputing.com thats portable across different application servers. If you are using WebLogic, they have a time service.
I believe you must be using an application server to deploy your bean. I have done that in Weblogic 5.1 and believe this can be implemented anywhere. write your scheduler is java and you can call that scheduler at startup be defining the following property in weblogic.properties file.
weblogic.system.startupClass.startup = <name of scheduler class>
Now write your scheduler class in such a way so that it will read a properties file say scheduler.properties where you can define which classes to run, when and at what frequency. Well It is kind of tricky but it works perfect for me.
What you are looking for is a time service.
Most of the app servers provide it .. but since it is not a part of the j2ee spec itself, the usage might differ from app server to app server.
If you are using web logic then thy out the following link
http://e-docs.bea.com/wls/docs61/////time/time.html
regards,
Abhishek.