tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Classloader
Date Thu, 16 Nov 2000 18:01:26 GMT
Rob Shaw wrote:

> Given that I have 2 "contexts" defined (which I'm assuming
> each has thier own classloader).

That is correct.

> After making a request to the same servlet within each
> context, I'm witnessing the creation of seperate instances
> of the servlet per context, which I would expect, but
> I'm also witnessing the sharing of classes
> that have static members.
> Is this intentional, or is this a bug?

It depends on where the classes are loaded from.  The following details
are Tomcat-specific, but something similar is probably true for most

The web-app class loader that Tomcat creates for each web app will
delegate to the system class loader (i.e. the one that processes the
CLASSPATH) if a class is not found in "/WEB-INF/classes" or
"/WEB-INF/lib/*.jar".  In such a case, there will be only one copy of
such classes (because the system class loader is delegated to from each
web app), so statics are shared across web apps.

On the other hand, if you made a copy of the class underneath WEB-INF
for each web app, the statics would *not* be shared.

> According to Servlet 2.2 spec:
> > 4.6 Reloading Considerations
> >...
> > Therefore, when a Container Provider implements a class
> > reloading scheme for ease of development, they must ensure
> > that all servlets, and classes that they may use, are loaded
> > in the scope of a single class loader guaranteeing that the
> > application will behave as expected by the Developer.
> ...

In fact, there is an explicit documented restriction in Tomcat that it
only applies to classes found under WEB-INF -- class reloading for
things found on the system class path is not supported.

> Thanks,
> Rob.


View raw message