• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletContext : Please Help

 
Mahesh Rana
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,
I want to keep only one instance of an object
on my Jserv which should be available to all the servlets all the time.
Before I modify the code, I am seeking for your suggestion.
IS IT OK TO DECLARE AND INITIALISE THAT OBJECT IN THE SERVLETCONTEXT CLASS ? WILL IT WORK ?
Thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would certainly do it with a "Singleton" pattern class. You could store the resulting object in the ServletContext - as long as there is only one server. Surely you are not talking about modifying ServletContext - no need for that.
Bill
------------------
author of:
 
Mahesh Rana
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill.
 
Jim Baiter
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to play devil's advocate, you might want to look at this though:
http://c2.com/cgi/wiki?SingletonsAreEvil
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic