tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Rudnicki <jdr5l...@pacbell.net>
Subject Re: Singleton Revisited
Date Fri, 18 Aug 2000 06:25:59 GMT
Message
> > 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.

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
performance.

Jim





Mime
View raw message