Re: Accessing static variable from different webapps
Thanks a lot for helping me understand all this concepts about classloading. I found a pretty good article on class loading in java. http://www.onjava.com/pub/a/onjava/2005/01/26/classloading.html Thanks, Anshaj On Thu, 03 Feb 2005 22:25:53 +0100, Mario Winterer <[EMAIL PROTECTED]> wrote: > For more information on tomcat's classloading concept have a look at: > http://jakarta.apache.org/tomcat/tomcat-5.5-doc/class-loader-howto.html > > As you can see there, Tomcat instantiates a classloader for each web > application. So if you put a class - let's say "Global" - inside the > "WEB-INF/classes" directory of each of two of your web applications, it > will be loaded twice. As a fact, a static variable of the "Global" class > - let's say Global.myVar - will exist twice too! > But if you put your "Global" class into the %TOMCAT_HOME%/shared/classes > directory ONLY (important: you must remove all occurences of your > "Global" class from the webapps-classes directories to make this work!), > it will be loaded by the "shared"-classloader. Because of the fact that > the shared classloader is the parent classloader of all > webapp-classloaders, every web-application can access the classes loaded > by the shared classloader. > > But holding resources in static variables inside the shared/classes > directory there is not recommmended! Better add a JNDI-resource to your > Tomcat's JNDI-context! This is done in server.xml inside the > -element* *(see > http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/globalresources.html). > > Best regards, > Tex > > > >Thanks for your reply. I think JVM rules said that there should be 1 > >reference per JVM for a static variable. Tomcat class loader creates > >separate instance of a static variable for each webapps. I am just > >trying to understand how class loader works in tomcat. > > > >Thanks, > >Anshaj > > > > > >On Thu, 03 Feb 2005 06:41:29 -0500, Tim Funk <[EMAIL PROTECTED]> wrote: > > > > > >>Put the class in the common or shared classloader. > >> > >>-Tim > >> > >>Anshaj Mathur wrote: > >> > >> > >> > >>>Dear group, > >>> > >>> I have public class which contains a static > >>>variable type integer. I am running different webapps > >>>inside single instance of tomcat. I initiated this > >>>class in different webapps. I increased the count from > >>>a webapp and tried to see it from different webapp. I > >>>found that count was not increased in other webapp. It > >>>was showing the original count. > >>>Am I braking any laws of tomcat security. > >>> > >>> > >>> > >>- > >>To unsubscribe, e-mail: [EMAIL PROTECTED] > >>For additional commands, e-mail: [EMAIL PROTECTED] > >> > >> > >> > >> > > > > > > > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- v1.2a r TW 0/0/ FD + 0 DSotM 3 100 21.3% <3jan5> - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Accessing static variable from different webapps
Yes it makes perfect sense. Thanks for clarify some of the basic concepts to me. Regards, Anshaj On Thu, 3 Feb 2005 06:52:55 -0600, Caldarale, Charles R <[EMAIL PROTECTED]> wrote: > > From: Anshaj Mathur [mailto:[EMAIL PROTECTED] > > Subject: Re: Accessing static variable from different webapps > > > > Thanks for your reply. I think JVM rules said that there should be 1 > > reference per JVM for a static variable. > > It's one reference per classloader, not JVM. > > > Tomcat class loader creates separate instance of a static > > variable for each webapps. I am just trying to understand > > how class loader works in tomcat. > > That's because there's a separate classloader for each webapp, along with a > few others. Take a look at: > http://jakarta.apache.org/tomcat/tomcat-5.0-doc/class-loader-howto.html > > - Chuck > > THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY > MATERIAL and is thus for use only by the intended recipient. If you received > this in error, please contact the sender and delete the e-mail and its > attachments from all computers. > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- v1.2a r TW 0/0/ FD + 0 DSotM 3 100 21.3% <3jan5> - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Accessing static variable from different webapps
Thanks for your reply. I think JVM rules said that there should be 1 reference per JVM for a static variable. Tomcat class loader creates separate instance of a static variable for each webapps. I am just trying to understand how class loader works in tomcat. Thanks, Anshaj On Thu, 03 Feb 2005 06:41:29 -0500, Tim Funk <[EMAIL PROTECTED]> wrote: > Put the class in the common or shared classloader. > > -Tim > > Anshaj Mathur wrote: > > > Dear group, > > > > I have public class which contains a static > > variable type integer. I am running different webapps > > inside single instance of tomcat. I initiated this > > class in different webapps. I increased the count from > > a webapp and tried to see it from different webapp. I > > found that count was not increased in other webapp. It > > was showing the original count. > > Am I braking any laws of tomcat security. > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- v1.2a r TW 0/0/ FD + 0 DSotM 3 100 21.3% <3jan5> - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Accessing static variable from different webapps
Dear group, I have public class which contains a static variable type integer. I am running different webapps inside single instance of tomcat. I initiated this class in different webapps. I increased the count from a webapp and tried to see it from different webapp. I found that count was not increased in other webapp. It was showing the original count. Am I braking any laws of tomcat security. Thanks for your suggestions. Regards, Anshaj -- v1.2a r TW 0/0/ FD + 0 DSotM 3 100 21.3% <3jan5> - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]