File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

automatic running servlet

 
manish ahuja
Ranch Hand
Posts: 312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
How can I automatically invoke a servlet periodically at specified time intervals, like cron?
Rgrds
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic