tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Angel Municio <muni...@email.com>
Subject RE: Singleton Revisited
Date Wed, 16 Aug 2000 16:45:05 GMT
Hi all,

Right now I'm using a PoolManager class (implemented as a Singleton class)
that returns connections to several web apps. But reading those mails makes
me realize that this is asking for trouble.  How should I implement this
then?

Thanx for your help
angel

-----Original Message-----
From: Craig McClanahan [mailto:Craig.McClanahan@eng.sun.com]
Sent: Wednesday, August 16, 2000 12:15 PM
To: tomcat-user@jakarta.apache.org
Subject: Re: Singleton Revisited


Jim Rudnicki wrote:

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

Even in a single-JVM environment, a typical servlet container implementing
the
2.2 spec will have more than one class loader defined.  For example, Tomcat
defines a class loader per web application -- that is how it implements
making
classes under WEB-INF/classes and WEB-INF/lib available to each particular
app.

The behavior of statics (in particular, whether they are global across web
apps
or not) depends on which class loader loaded that class, and therefore
depend
on how your particular servlet container does this.  You cannot count on
consistency across platforms.

For sharing information *within* a web app, the singleton pattern
implemented
as a static variable is feasible and portable (although I dislike it for
"personal bias" reasons -- I've seen too many apps get messed up because any
code in the entire application can mess with those global variables, making
bugs hard to track down).  For sharing information *across* web apps, the
servlet spec advises using external mechanisms (files, databases, directory
servers, etc.) to maintain portability.

Craig


-----------------------------------------------
FREE! The World's Best Email Address @email.com
Reserve your name now at http://www.email.com



Mime
View raw message