• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Timed Reloading

 
Timy McTipperstan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you point me to an example of how that would work?
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic