• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Servlet Timed Reloading

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you point me to an example of how that would work?
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic