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 Wed, 16 Aug 2000 05:18:33 GMT
> 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.

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

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.




Mime
View raw message