tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Plukker <>
Subject Re: Are static vars VM dependend or ClassLoader dependend [offtopic]
Date Wed, 19 Jun 2002 12:01:58 GMT
Hello Stefan,

Based on my testing I can say this:
Webapps are loaded in a seperate class loader, each webapp has it's own.
(this goes for classes in the WEB-INF/classes and WEB-INF/lib)
If you use a singleton pattern it will be singleton for it's class 
loader (WebappClassLoader).
(more info classloader in tomcat docs).
therefor a singleton is not usefull if you want it to act a global 
singleton for each webapps.

However, I have been testing with crossContext, then you can use that 
way you can use classes from one context with another.
If you bind a Singleton to the JNDI context (look at the JNDI howto in 
tomcat docs) you should be able to make a Singleton global for webapps 
that are cross context.

How do you share an instance of an object now?

Good luck,

Stefan Langer wrote:

>This is a little off topic. According to documentation each webapplication
>is loaded by a different classloader. If I understand this correct that
>means each ServletContext is loaded with a different ClassLoader.
>In my webapplication I'm using a singleton pattern to load some needed
>The static variable implementing the singleton is used by more than one
>I'd like to know is this singleton a singleton in the ServletContext or is
>it a singleton to the JVM? Stated differently is the static variable the
>same for each webapplication in the Tomcat instance or does each Context
>have its own copy of the static since each context is loaded by a different
>classloader. As far as my testing has gotten I think that the static is only
>available once in the Tomcat installation.
>Can anybody confirm this or for that deny it??
>Thank you very much in advance
>Stefan Langer
>To unsubscribe, e-mail:   <>
>For additional commands, e-mail: <>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message