aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Cyclic method execution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Cyclic method execution" Watch "Cyclic method execution" New topic
Author

Cyclic method execution

Karol Susz
Greenhorn

Joined: Mar 19, 2010
Posts: 3
First of all Welcome !

I have a question. I have web app (written in struts, app buisness logic is in EJB) and I want it (www) to cyclic invoke some service method from EJB in defined period of time. Now I have service jsp page with "meta http-equiv="Refresh" and the method is invoked in struts Action. This is not good for me because it requires "user-admin" interaction with the page. I need solution transparent to the user. I consider servlet with some timer but now I see it is not good ide at all. Is there some good and simple solution for my problem. This should be something in shape of little deamon running in background on www server as a part of app and with ability of reading 2 parametrs from setup.properties: interval of invoking service method and on/off param.

Could someone help me with some ide ?
Krum Bakalsky
Ranch Hand

Joined: Mar 14, 2010
Posts: 46
You could try using EJB timers or some open source Java background processing tool, such as Quartz job scheduler. It has JavaEE integration right inside the servlet layer.

I wish you success with your project!


SCJP 6 (86% - the hard way), SCBCD 5 (81% - the hard way)
Karol Susz
Greenhorn

Joined: Mar 19, 2010
Posts: 3
Despite my previous hunch that servlet with timer is bad idea, this solution accoured to be working just fine. Short description what I have done to solve my specific problem (as I mentioned before it had to be simple):
- new servlet with <load-on-startup>1</load-on-startup> set in web.xml (app server runs it when app starts - this is what i needed)
- parameters from setup.properties are being read in servlet (in method invoked from init)
- using quartz library a job is being created and initialized with parameters (added 2 new classes: Job and scheduler )
- EJB facade service method is being invoked from job class

Works fine, transparent to the user, does not disturb in normal using the application. Mission accomplished.

Krum thank You for reply, it helped me to verify my solution.
Krum Bakalsky
Ranch Hand

Joined: Mar 14, 2010
Posts: 46
Glad to know that my advice has helped you.

Didn't you just use the EJBInvoker job, which comes with the Quartz distribution ?
Karol Susz
Greenhorn

Joined: Mar 19, 2010
Posts: 3
Basically yes, I used Quartz scheduler to run my job (which implements Quartz Job). All this stuff is initialized from a servlet.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cyclic method execution