wood burning stoves 2.0*
The moose likes Servlets and the fly likes automatic running servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "automatic running servlet" Watch "automatic running servlet" New topic
Author

automatic running servlet

manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
Hi
How can I automatically invoke a servlet periodically at specified time intervals, like cron?
Rgrds
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi Manish
As far as I can think, following could be possible solutions
1. write a timer (using Timer and TimerTask classes) where you put URLConnection code to your servlet in the TimerTask so whenever the task is scheduled it makes URLconnection...that way you can invoke the servlet
- you would have to invoke this timer somehow first time though...
Possible PROBLEM:
- if the webserver restarts (jvm dies for sometime) then you would loose this timer so this solution doesn't provide you persistent store you know
To solve the above problem,
- you can make the scheduling information about the servlet persistent
- you can write a servlet that on webserver start gets initiated (this setting would be specific to each webserver configuration things)
- make that servlet load the persistent data and start timer object accordingly...
does this help?
Regards
Maulin
Bart Fransen
Greenhorn

Joined: Feb 12, 2004
Posts: 4
Hi Manish,
I don't know which app server your running on, but if you're using Resin like me, there is an option in the configuration file to run servlets automatically at certain times. Check out ...
<servlet servlet-name='alarm' servlet-class='com.foo.bar.Alarm'>
<run-at period='1m'/>
</servlet>
This will run the Alarm servlet service() method every minute.
I don't know if any of the other app servers out there have the same functionality, but check out the docs ...
Hope that helps,
Bart
 
 
subject: automatic running servlet
 
Similar Threads
javascript, servlets and SVG
Export in Excel
How can I change the sdk version of Websphere 4 if I already install it
Is there any way to get Servlet Init Parameter using EL?
Capturing Form Data