dcsimg
Is it possible to build a timed task within a EJB?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   josel_lucini
Posted On:   Monday, June 17, 2002 12:22 AM


I would like to know how to build a timer task that runs periodically within the J2EE framework (I mean, using EJBs).


I've thought in a Statefull Session Bean containing a controlled infinite loop with some logic to wait and launch a task in a different thread.


I've read that the code within an EJB should not include any multithread code (runnning thread objects, wait for a period of time, ...), so I'm in a dead end.


Could I use the 1.3 Timer class instead of an object implementing a thread and running it within a Stateful Session Bean?

Thanks for your suggestions.

Re: Is it possible to build a timed task within a EJB?

Posted By:   Laurent_Mihalkovic  
Posted On:   Monday, June 17, 2002 09:55 AM

Josel,

The purpose of EJBs is to manage the instanciation and life span of object that would most likely have a defined life span. Like you mention, The solution is outside of EJBs, as they *shall not* deal with threads AT ALL.

At this point, there is no facility in the J2EE spec for creating standard cron-like services. However, most of the big players have developped their own API for that purpose. You can code for these APIs. They have also developed APIs to add your own code to the server's startup procedure.

If you still want to create a solution that works accross the board, I suggest you look into creating a servlet that will be instanciated when your web application is started, and that would include your timer facility. Servlets have no problem spawning threads, and you have the guaranty that the service will start with the web application. You could use the servlet life cycle API to persist the list of tasks when the server is shutdown.

hope this helps
laurent

About | Sitemap | Contact