aspose file tools*
The moose likes Servlets and the fly likes Servlet Timed Reloading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Timed Reloading" Watch "Servlet Timed Reloading" New topic
Author

Servlet Timed Reloading

Timy McTipperstan
Ranch Hand

Joined: Feb 17, 2005
Posts: 32
Not sure this is the correct way of doing this, but I have a servlet that builds a list on startup and makes it available to the application. However one issue my creep up, is if I only restart teh app 3 times a week (automated), then that list gets updated 3 times a week, there that list could change once a day.

Can I use a cron command to re-run that servlet, or is there some better solution.
Ed B.
Greenhorn

Joined: Jul 21, 2003
Posts: 9
Why not preiodically build it? Maybe using a thread which goes to sleep until the next schedule time or your application creates a thread which builds the list.



Adnan
Timy McTipperstan
Ranch Hand

Joined: Feb 17, 2005
Posts: 32
Can you point me to an example of how that would work?
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
I wrote a class for exactly this purpose. It's called TtlReference. Basically, it maintains a reference to an object for a TTL (time to live) amount of time. A separate thread runs in the background to clear references that have expired.



James Carman, President<br />Carman Consulting, Inc.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you prefer not to get into threading (James did a nice job (t.setDaemon(true)), a one line cron job can get you the same results.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61205
    
  66

a one line cron job can get you the same results.


That's how I do a lot of timed stuff. But it assumes you are using a real operating system.
[ March 02, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Yes, cron will work fine if you have everything cached for the same duration (unless you want to maintain a bunch of cron commands). My solution is all Java and it works pretty well. There's no need to write a servlet which knows that it has to reload the objects at all. Your logic which accesses the data has to do a "lazy load" though. Actually, the real framework (I removed some code) has the option to place a listener on the reference so that you can auto-refresh the data behind the scenes, reducing the risk of a client having to wait for the refresh.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Timed Reloading