tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Rudnicki <>
Subject Re: Singleton Revisited
Date Fri, 18 Aug 2000 06:25:59 GMT
> > in init() you call getInstance() and store the reference in a member of
> > servlet class.  As long as the servlet exists, the singleton will exist.
> > not use getInstance() in the service() method.  What is noted in that
> > 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
> Is it a dangerous thing? Why? In my environment, It seems to work fine.

Okay, it depends on your goals.  Some of my uses for a Singleton are the
goal of efficiency in reusing one object and for the goal of avoiding
construction and destruction hits.  Your db pool probably needs both of
these.  You do not want the entire pool to be gc'd and rebuilt between every
service().  To ensure that, something must retain a copy of the reference
you get from getInstance().  If you just store it in a local variable, it
goes away on return;

Now if you let go of your references, your servlets still will work--just
maybe not well.  You could be invoking the DBConnectionPool constructor on
_every_ doGet().  This would not show as a failure, just real slow


View raw message