• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • 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
 
Michael Zalewski
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • 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
  • 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.)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!