Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 25431 invoked from network); 2 Jun 2005 12:49:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 Jun 2005 12:49:21 -0000 Received: (qmail 53481 invoked by uid 500); 2 Jun 2005 12:48:58 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 53471 invoked by uid 500); 2 Jun 2005 12:48:58 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 53455 invoked by uid 99); 2 Jun 2005 12:48:58 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from ext-ch1gw-2.online-age.net (HELO ext-ch1gw-2.online-age.net) (216.34.191.36) by apache.org (qpsmtpd/0.28) with ESMTP; Thu, 02 Jun 2005 05:48:55 -0700 Received: from int-ch1gw-5.online-age.net (int-ch1gw-5 [3.159.232.69]) by ext-ch1gw-2.online-age.net (8.12.9/8.12.9/990426-RLH) with ESMTP id j52CmceP027031 for ; Thu, 2 Jun 2005 08:48:38 -0400 (EDT) Received: from cinmlef07.e2k.ad.ge.com (localhost [127.0.0.1]) by int-ch1gw-5.online-age.net (8.12.9/8.12.3/990426-RLH) with ESMTP id j52CmbXs006494 for ; Thu, 2 Jun 2005 08:48:37 -0400 (EDT) Received: from BUDMLVEM05.e2k.ad.ge.com ([3.159.52.50]) by cinmlef07.e2k.ad.ge.com with Microsoft SMTPSVC(6.0.3790.211); Thu, 2 Jun 2005 08:48:29 -0400 X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: WebappClassLoader - don't understand what's happening Date: Thu, 2 Jun 2005 14:50:28 +0200 Message-ID: <52D9CED6CB3BFC4FA640275E0114E231037A47A2@BUDMLVEM05.e2k.ad.ge.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: WebappClassLoader - don't understand what's happening Thread-Index: AcVnb0JVDUAmT/C/RsmAnYJuo3swGAAAAzjA From: "Herrmann, Sascha \(GE Healthcare\)" To: "Tomcat Users List" X-OriginalArrivalTime: 02 Jun 2005 12:48:29.0593 (UTC) FILETIME=[60620890:01C56771] X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N > Any library having static methods like > SomeLibraryClass.setXYZ(xyz); > SomeLibraryClass.getXYZ(xyz); Wow, wow, wow .... . You mean any class that has static methods gets = shared?? Any class that calls static methods? Could you explain that a bit = further, please? > so i doubt usefull informations comes from it.=20 It works for all the other methods I put this code in. It seems that = Tomcat assigns the CL to thread when it's fetched from the pool. It's definitely the case. We have a static log variable in the classes. = It holds the log4j logger reference. All the debug output from the class goes into the log file of the = application that started first (the one that loaded the class). Even the output when I use the app that was started second. That's how I = noticed in the first place. Are you familiar with the classloading stuff? I was wondering ... when the WebappClassLoader doesn't find the class in = its path, and then delegates the loading to the shared classloader ... and when then the shared classloader loads the class .... who resolves = the dependecies of this loaded class? Does the WebappClassLoader get a = shot first, or is it still the shared classloader? What if the shared classloader loads a class, and then cannot resolve a = referenced class (because it's in one of the app's WEB-INF\lib = directories) ... how does he determine which child WebappClassLoader he is to use? And = who is registered in the JVM then as initiating classloader? I am asking because we have classes in our shared\lib directory. Those = classes use a factory pattern to instantiate classes (that can be in the = WEB-INF\lib dirs). Now, I wonder how these classes are loaded, that the = factory class in shared\lib needs? Or am I thinking in the wrong direction? Does the WebappClassLoader = always try first? Damn, I wish I would know this classloading stuff better. Do you have an idea why I cannot get logging output from the = WebappClassLoaderS? Sascha > -----Original Message----- > From: delbd [mailto:delbd@oma.be]=20 > Sent: Thursday, June 02, 2005 2:32 PM > To: Tomcat Users List > Subject: Re: WebappClassLoader - don't understand what's happening >=20 >=20 > Le Jeudi 2 Juin 2005 13:49, Herrmann, Sascha (GE Healthcare) a =E9crit = : > > Thanks for your reply. > > > > It could be. How is a class "pushed" to a shared library? >=20 > Any library having static methods like > SomeLibraryClass.setXYZ(xyz); > SomeLibraryClass.getXYZ(xyz); >=20 > > > > I used the following code: > > > > System.out.println( "BoneDBTransactionImpl2 LOADING=20 > > ***************************************" ); System.out.println(=20 > > "Thread Classloader is: " +=20 > > Thread.currentThread().getContextClassLoader() );=20 > System.out.println(=20 > > "Hash: " + > > Thread.currentThread().getContextClassLoader().hashCode() );=20 > > System.out.println( "Class: " + > >=20 > Thread.currentThread().getContextClassLoader().getClass().getName() ); > > System.out.println( "--------------------------- " ); > > System.out.println( "Class Classloader is: " + > > BoneDBTransactionImpl2.class.getClassLoader() );=20 > System.out.println( "Hash: > > " + BoneDBTransactionImpl2.class.getClassLoader().hashCode() );=20 > > System.out.println( "Class: " + > >=20 > BoneDBTransactionImpl2.class.getClassLoader().getClass().getName() );=20 > > System.out.println( "BoneDBTransactionImpl2 LOADING=20 > > ***************************************" ); > > >=20 > Tss tss tss, the Threads instances are started by=20 > catalina-http and shared inside a Thread pool amongst tomcat=20 > application if am not wrond, so i doubt usefull informations=20 > comes from it.=20 > Only usefull information should comes from > BoneDBTransactionImpl2.class.getClassLoader() as this is the=20 > classloader which will load any class needed by=20 > BoneDBTransactionImpl2. >=20 >=20 > > I put this into a static initializer block of a class that=20 > is in a jar=20 > > in both WEB_INF\lib directories. I also added this code the=20 > > constructor of that class. And to make sure to see what=20 > loader belongs=20 > > to what app I also added the code to some methods of=20 > classes that are=20 > > either in app A or in app B and not in both. > > > > I start app A. The output shows that > > > > - the class is loaded in app A by WebappClassLoader with hash A > > - the instance is created in app A using the Class loaded by=20 > > WebappClassLoader with hash A. - Thread context classloader is=20 > > WebappClassLoader with hash A. > > > > Then I start app B. The output shows that > > > > - the instance is created in app B using the Class loaded by=20 > > WebappClassLoader with hash A - Thread context classloader is=20 > > WebappClassLoader with hash B. >=20 > Strange indeed, so you mean when starting app B, the static block of > BoneDBTransactionImpl2 is never executed? If that's the case=20 > this indeed mean the class was already loaded before. Either=20 > this mean you have another lib in webapp B requiring=20 > BoneDBTransactionImpl2 and you didn't see the static init=20 > message 50 lines before ;), either you indeed have something shared. >=20 > One easy way to check > In webapp A, create a servelt which will set to 1 a static boolean in > BoneDBTransactionImpl2 and in webapp B, set another servlet=20 > which will read the value of this boolean.=20 > first access B servlet to ensure boolean is set to false=20 > acces A servlet to switch boolean to true re-access B servlet=20 > to check if boolean has switched value in B webapp >=20 > If that's the case, this really mean class is shared by=20 > webapp class loaders, serious problems ahead for tomcat team ;) >=20 >=20 >=20 > > > > The class exists in jar files in both WEB-INF\lib=20 > directories, but not in > > any other lib directory. And - if the class was loaded by a shared > > classloader, shouldn't the xxx.class.getClassLoader() return the > > StandardClassLoader? > > >=20 > dunno >=20 > > I must admit that I am not too familiar with the deeper=20 > concept of J2EE > > classloading apart from the information found on some web pages. > > >=20 > me too ;) however, separation in webapps mean every ressource=20 > in a .war is not=20 > to be shared with any other webapp. >=20 >=20 > > So, if the class indeed is loaded by WebappClassLoader A,=20 > how can it be > > "pushed" to become a shared one? And how can I prevent this=20 > from happening? > > Or am I making a mistake reading the output? I am sure that=20 > the class is > > not loaded again. >=20 > see message above, i just didn't know how you concluded the=20 > class was shared,=20 > one common error is to give an instance of some object to a=20 > shared library=20 > and retreive it in another webapp, not understanding this=20 > object you are=20 > manipulating is a stranger ;) not your case scenario you describe. >=20 > > > > I checked the sources in Apache's CVS. I noticed that there=20 > is quite some > > debugging put into WebappClassLoader. But I can't get my=20 > server to log > > these messages. I have the log4j and commons logging jars=20 > in my common\lib > > directory and my log4j.properties (root logger set to debug) in my > > common\classes directory. I also set the debug to "4"=20 > everywhere in my > > server.xml. I see some catalina debug messages, but I cannot see the > > messages from the WebappClassLoader. So what am I doing=20 > wrong? I believe > > the debug output would be very helpful in understanding the problem. >=20 > Yes have same problem here to get usefull log messages from=20 > Realms. Seems you=20 > have to modify directly the logging level in your java home,=20 > logging.properties (and setting it to debug for whole jvm is=20 > VERY verbose) >=20 > > > > Sascha > > > > > -----Original Message----- > > > From: delbd [mailto:delbd@oma.be] > > > Sent: Thursday, June 02, 2005 12:33 PM > > > To: Tomcat Users List > > > Subject: Re: WebappClassLoader - don't understand what's happening > > > > > > This indeed should not happen as this would break sun specs. > > > I would be quite surprised it it was at all possible :/ How > > > did you conclude the webappclassloader is sharing the class > > > between webapps in your case? > > > > > > Are you sure you are not mistakenly using a shared class? > > > > > > Not only does every webapp has his very own > > > webappclassloader, but if you reload the webapp (using the > > > manager/html interface) this should also create a new > > > webclassloader and reload all classes (did you check it was > > > the case?). > > > > > > Am also using tomcat 5.5.7 here, with jdk 1.4.2_05-b04 and we > > > didn't notice such a problem. We can deploy several webapps, > > > all using a library in WEB-INF/lib which is crating > > > singletons. All webapp has it's own sets of singletons. > > > > > > Could it be that you are in fact doing such scenario? > > > > > > - create an object of class A in webapp1 using webappclassloader1 > > > - push this object to some library shared between webapplications > > > - retrieve the object from shared library in webapp2 (as this > > > is via a shared library, it's possibile to do and you and up > > > manipulating in webapp2 an object who's classloader is > > > webappclassloader1) > > > - in webapp2, calls something like a.createB() to get an > > > object of class B and be surprised that the class of B was > > > created using webappclassloader1 > > > > > > Le Jeudi 2 Juin 2005 10:59, Herrmann, Sascha (GE=20 > Healthcare) a =E9crit : > > > > We are facing a problem with Tomcats WebappClassLoader. > > > > We deploy several of our own applications on one Tomcat server. > > > > > > > > It seems that the WebappClassLoaderS are not isolated but share > > > > classes instead. Why would that be? > > > > > > > > Judging from the (well, outdated) classloader=20 > documentation, this > > > > should never happen. > > > > If an application tries to use a class, and the class is in > > > > > > a jar in > > > > > > > its WEB_INF\lib directory, then the class should be=20 > loaded by the > > > > application's very own WebappClassLoader. It should not be > > > > > > available > > > > > > > to other WebappClassLoaderS, isn't that correct? I quote: > > > > > > > > "All unpacked classes and resources in the /WEB-INF/classes > > > > > > directory > > > > > > > of your web application archive, plus classes and=20 > resources in JAR > > > > files under the /WEB-INF/lib directory of your web application > > > > archive, are made visible to the containing web > > > > > > application, **but to no others**." > > > > > > > Instead of sharing the class, the second WebappClassLoader > > > > > > should load > > > > > > > the class again, shouldn't it? > > > > So why does a WebappClassLoader here re-use a class already > > > > > > loaded by > > > > > > > the WebappClassLoader of another application? > > > > > > > > We're running 5.5.7 on JDK 142_08. > > > > > > > > Thanks in advance! > > > > > > > > > > > > Sascha Herrmann > > > > Engineering (Java) > > > > GE Healthcare > > > > Technologies > > > > > >=20 > --------------------------------------------------------------------- > > > > > > > To unsubscribe, e-mail:=20 > tomcat-user-unsubscribe@jakarta.apache.org > > > > For additional commands, e-mail:=20 > tomcat-user-help@jakarta.apache.org > > > > > > -- > > > David Delbecq > > > Royal Meteorological Institute of Belgium > > > > > > - > > > Is there life after /sbin/halt -p? > > > > > >=20 > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org > > > For additional commands, e-mail:=20 > tomcat-user-help@jakarta.apache.org > > > >=20 > --------------------------------------------------------------------- > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org > > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org >=20 > --=20 > David Delbecq > Royal Meteorological Institute of Belgium >=20 > - > Is there life after /sbin/halt -p? >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org >=20 >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org