tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Angel Municio <>
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

Thanx for your help

-----Original Message-----
From: Craig McClanahan []
Sent: Wednesday, August 16, 2000 12:15 PM
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
> all worried.

Even in a single-JVM environment, a typical servlet container implementing
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
classes under WEB-INF/classes and WEB-INF/lib available to each particular

The behavior of statics (in particular, whether they are global across web
or not) depends on which class loader loaded that class, and therefore
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
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.


FREE! The World's Best Email Address
Reserve your name now at

View raw message