tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Plukker <rich...@bowtie.nl>
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,
Richard

Stefan Langer wrote:

>Hello
>
>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
>ressources.
>The static variable implementing the singleton is used by more than one
>webapplication.
>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:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>
>
>
>  
>




--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message