I've never played with tomcats class loaders but I was wondering why you want to place a "distinct" class so high in the Tomcat classloader tree.
See the  http://tomcat.apache.org/tomcat-4.1-doc/class-loader-howto.html

I think the only reason it could have behaved at all as distinct classes in the first place is because of Tomcats unusual class loading behavior...

In "normal class loading" theres a "ask your mama" principle at work... so this is the wrong impression.....
All the advice I've found through searching the web suggests this cannot happen because the two apps use different class loaders. But it definitely is happening.
A class loader will normally "ask its mama" before it tries to load a class.... so one would expect it to move up the tree. If 2 children share the same "mama" and mama can see the class, mama will load it.... normally.

Webapps break this rule.... if they can see the class, then they ignore mama.... but if they cant see the class, then they will ask mama.... this is unusual in terms of class loading, but its there for our sanity, because as users, the classes we stick in the web app, we expect to come first because we thinking in the box.... however for normal applications if the class has been loaded by mama already, we dont care where it comes from.

I would expect in a normal application, for the class to be shared... and this goes for tomcat as well, EXCEPT if the classes were ALSO in the web-app lib. So.... and I'm guessing.... I think all thats happened is those classes have been taken out of the Web-App/lib and if you stick them back in there, they will behave distinctly again. They have no choice now but to ask mama.... and if mama has already loaded the class... she wont do it again, she'll share it.

Remember that this may happen indirectly.... and this is wot I'm not sure of... if an lib under web-app/lib referred to the common class, then I'm not sure wot the class loader would do... ie the web-app class loader will pull the class in from web-app/libs and when it finds the dependency.... will it get it from mama and treat it as a web-app class... or as a common one??? Thing about class loaders is they are left very much up to the discretion of the programmer... can make them do anything, so the only thing that matters is how the tomcat developers want you to use them...

Anyway... I think you playing with fire... I mean if you stuck a singleton in a common classloader... you would expect it to be shared.... so why dont you just move them down the tree.... take them out of common and give each web-app its own copy.... unless you want it to behave as a shared static class.

I think the way its structured now, static fields sharing makes sense... that they behaved distinctly at all... is weird.


----- Original Message ----- From: "Roger Parkinson" <[EMAIL PROTECTED]>
To: <users@tomcat.apache.org>
Sent: Monday, May 07, 2007 5:02 PM
Subject: [Fwd: static fields suddenly started sharing]


I have two different applications and they both make use of a common jar library. The common library has several static fields. Up until last week the static fields in one application never saw the static fields in the other but I changed something and suddenly they do. All the advice I've found through searching the web suggests this cannot happen because the two apps use different class loaders. But it definitely is happening.
I'm getting it on Tomcat 4.1 and 5.5 (my two live platforms).

I am trying to figure out what I changed to make this happen because it is causing me problems. The changes I made were a restructure, shifting things around into different folders in my eclipse project, but the same jar files are in WEB-INF/lib as there always were.

Can anyone suggest where I should be looking? I'm wondering if I am managing to call something I shouldn't too early in the application initialisation. Each of the apps has a context listener that does some stuff on startup of the app (including initialising some statics), but they haven't changed since it was working. I still have the older structure and it still works, and I can't see any relevant changes,

Thanks for any help
Roger



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to