File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 12836
    
    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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ServletContext : Please Help