tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: question on servlet contexts and class loaders and statics
Date Fri, 15 Dec 2000 19:04:49 GMT
"Komatineni, Satya" wrote:

> Take the scenario where multiple web applications are running under the same
> JVM. Each of these web applications will have their own class loader and
> servlet contexts.
> Can they share/use the same utility jar file?
> what if the jar file has statics?
> For example:
> class A
> {
>         public static String name="global";
> }
> Do statics exist for the entire JVM? or one for each class loader?  If they
> are for the whole JVM what happens if two web apps try to access the same
> static variable?

It depends on where the class itself is loaded from.

If the class containing the static is loaded from WEB-INF/classes or
WEB-INF/lib, then the statics will be global only to that web app.  If the class
containing the static is loaded from the system class path, there will be only
one copy globally.

WARNING:  depending on the existence of a shared class path you can do this with
is not described in the servlet specification, and is not guaranteed to be
available on every servlet container (although it is usually available).  For
maximum portability, you should use external mechanisms (files, databases, EJBs,
directory servers, etc.) to share information across webapps.

> Thanks
> Satya?

Craig McClanahan

View raw message