• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ok to run thread in load-on-startup servlet?

 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All-
I trying to come up with a simple solution for distributed cache updates across multiple servlet engines (without using MQ/JMS) ...
I'm thinking of writing a singleton class called by a load-on-startup servlet to monitor for changes in another servlet engine's cache so servers can sync up their cache...
when servlet engine 1 updates its cache, a DB update is posted (poor man's MQ)...servlet engine 2's thread reads this update and is triggered to update it's own cache...times of last update are kept in each Servlet Context ... my question is:
is this OK to do, have a long running thread like this? (Isn't that essentially what a listener is anyway?)
thanks,
Max Tomlinson
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start your thread in Servlet.init().
Handle shutdown in Servlet.destroy().
You should be fine.
 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Michael-
Thanks -
(BTW I should have said we're on 2.2 so can't leverage any of the 2.3 stuff.)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic