This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlet Refreshing at Regular Intervals 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 "Servlet Refreshing at Regular Intervals" Watch "Servlet Refreshing at Regular Intervals" New topic
Author

Servlet Refreshing at Regular Intervals

vaitheeswaran subramanian
Greenhorn

Joined: Jan 06, 2005
Posts: 15
I have a servlet that loads on start up. All it does is loads look up data and caches it. I want this servlet to reload at regular intervals (once in an hour) and refresh its cache. How do I do that?

Vaithee
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If your servlet is not responding to web request, it shouldn't be a servlet.
Use a ServletContextListener instead.
For making your object perform tasks at given intervals look at either java.util.Timer or, if you need more functionality look at the Quartz library.


Another approach is to go with a servlet, put the lookup code in doGet or doPost, and trigger it with a web request using wget and a cronjob. This keeps you from having to spawn your own threads in a web app.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
ashok ganesan
Ranch Hand

Joined: Jan 02, 2007
Posts: 50
[Removed Hi-Jack]
[ March 04, 2008: Message edited by: Ben Souther ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Hi Ashok,

Please enter your question in a new thread.
Adding to the bottom of someone else's is called hi-jacking and not a nice thing to do. It has a tendency to derail the conversation about the original poster's question.

-Ben
ashok ganesan
Ranch Hand

Joined: Jan 02, 2007
Posts: 50
oops sorry for the mistake
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Refreshing at Regular Intervals
 
Similar Threads
Automating Servlet Tasks
How To Trigger Timer Bean automatically in startup servlet?
For Load Balancing
Confuguring tomcat to Run Thread at rgular intervals of Time
Call a servlet in listener