Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

startup timer servlet  RSS feed

 
manish ahuja
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I need some info on how to go about implementing the same.
I have a requirement where in we need to prepopulate some reference data which will later
be used through out the application.
I am invoking this through a startup servlet. Now I need to do it once every day at a
scheduled time.
The other concern is this piece of code which I execute from the startup servlet
actually communicates with a webservice (third party) to get the data.
Now suppose the webservice is down or due to some error condition I am not able
to fetch the data we want to repoll the webservice at say some scheduled time interval
or say when it is up.

Kindly provide your suggestions on the same


Regards
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The mistake you have made is implementing it as a startup servlet and then trying to extend the idea to something that is not the responsibility of the servlet to manage.

The code should be removed from the servlet and placed in a new class. This class should be kicked off from a context listener, and the context listener should also start some scheduling code (like quartz) so that your new class can be called periodically. The only point this ties into the web application is the ContextListener.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David O'Meara:
the context listener should also start some scheduling code (like quartz) so that your new class can be called periodically.


You might want to try JDK's Timer and TimerTask if you do not need any advanced scheduling capabilities.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!