tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yun Sang Jung" <>
Subject Re: Singleton Revisited
Date Wed, 16 Aug 2000 07:17:17 GMT
width="1" height="1">
> > Exactly *how* dangerous is it to use a static (to implement the singleton
> > pattern) in a JSP/Servlet environment? In the thread on this subject from
> ...
> > Trouble, it seems, comes in several flavors: 1) Your "singleton" gets
> GC'd;
> in init() you call getInstance() and store the reference in a member of the
> servlet class.  As long as the servlet exists, the singleton will exist.  Do
> not use getInstance() in the service() method.  What is noted in that thread
> is how it should be I believe.

I have used DBConnectionPool manager which is implemented by Singleton Pattern in 
multi-threaded servlet environment. Because I have not done heavy load performance test, 
I'm not sure the danger about the potential Singleton Pattern.

Following above your notice, Should I never call getInstance method in doPost or doGet?
I have been calling getInstance in doPost and doGet method in serveral servlets.
Is it a dangerous thing? Why? In my environment, It seems to work fine.

> > 2) multiple instances of the "singleton" can get made as more than one
> class
> > loader and/or VM are involved;

Couldn't Singleton Pattern guaruntee single instance in JVM?
I'm very confused..

> Not an easy way around this.  If you have one server, one jvm, one
> classloader. then I would hope that the singleton holds up.  Now you have me
> all worried.


View raw message