Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes ServletContext  : Please Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "ServletContext  : Please Help" Watch "ServletContext  : Please Help" New topic
Author

ServletContext : Please Help

Mahesh Rana
Ranch Hand

Joined: Sep 05, 2001
Posts: 139
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

SCJP2
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
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

Joined: Sep 05, 2001
Posts: 139
Thanks Bill.
Jim Baiter
Ranch Hand

Joined: Jan 05, 2001
Posts: 532
Just to play devil's advocate, you might want to look at this though:
http://c2.com/cgi/wiki?SingletonsAreEvil
 
 
subject: ServletContext : Please Help
 
Similar Threads
Calling Servlet method from Bean
Question On Thread Safety
Storing InputStream object to Application scope in servlet and retrieving
ServletContext Doubt / Poll
passing ServletContext