Is a webapplication guaranteed to have the same ClassLoader for different Servlets?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Is a webapplication guaranteed to have the same ClassLoader for different Servlets?

Bugzilla from linuxhippy@gmail.com
Hi there,

I am currently implementing a servlet-interface and I want to hold
some server-wide valid data in SingleTons.
However several different servlets in the same webblication (outch,
buzzword) and all those servlets want to share data via the
singletons.

This works but I have fears that its maybe a bit dirty and not
guaranteed to work.
So is a weblication (one directory containing a Web-INF and the
several servlet-classes) guaranteed to be loaded by the same
classloader (and therefor share the same static fields?).

Thanks you in advance, lg Clemens


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
<a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Is a webapplication guaranteed to have the same ClassLoader for different Servlets?

Greg Wilkins-5

Clemens,

a webapp may have more than one classloader - BUT...
if it does, it will be in a hierarchy and only a single copy of
a class from WEB-INF/lib or WEB-INF/classes will get loaded.

Thus your statics will be context scope if your classes are in
the WEB-INF or JVM scope if they are on the system classpath.

Have you considered using context attributes instead of statics
for your components to communicate?

regards



Clemens Eisserer wrote:

> Hi there,
>
> I am currently implementing a servlet-interface and I want to hold
> some server-wide valid data in SingleTons.
> However several different servlets in the same webblication (outch,
> buzzword) and all those servlets want to share data via the
> singletons.
>
> This works but I have fears that its maybe a bit dirty and not
> guaranteed to work.
> So is a weblication (one directory containing a Web-INF and the
> several servlet-classes) guaranteed to be loaded by the same
> classloader (and therefor share the same static fields?).
>
> Thanks you in advance, lg Clemens
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> <a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
> _______________________________________________
> Jetty-support mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jetty-support
>



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support