You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Krishnakumar B <ww...@gmail.com> on 2005/09/13 05:38:32 UTC
Static Variables and ClassLoaders
Hi,
I have a doubt related to usage of Static Variables.
"Static Variables are scoped in the class they r defined. So if a
class is loaded by more than one classloader in same JVM then there
will be multiple copies within same JVM"
How do i used Config Id/Parent Id to ensure that 2 plans use the same
ClassLoader so that i get a single instance of static variable.
Regards
Krishnakumar B
Re: Static Variables and ClassLoaders
Posted by David Jencks <da...@yahoo.com>.
I think you have found the cause of the problems in your other post :-)
I'm assuming you are using M5/Head.
First, make sure that each jar appears in only one plan as a dependency
or as a module in an .ear.
Then, locate the plans that contain all the jars you need directly as
dependencies or as parents.
Pick one, and use it's configId as the parentId attribute of your plan.
Include the others using include elements, which have the same xml form
as dependency elements:
<include>
<uri>configuIdURI</uri>
</include>
There's an alternate format that may be convenient if you have your
configurations in a maven-like repository, see the schema.
For your example in the other post, if the jar containing the hello
class is in the j2ee application, setting the parentId of your plan to
the configId of the application and leaving out the dependency element
should be sufficient.
thanks
david jencks
On Sep 12, 2005, at 8:38 PM, Krishnakumar B wrote:
> Hi,
>
> I have a doubt related to usage of Static Variables.
>
> "Static Variables are scoped in the class they r defined. So if a
> class is loaded by more than one classloader in same JVM then there
> will be multiple copies within same JVM"
>
> How do i used Config Id/Parent Id to ensure that 2 plans use the same
> ClassLoader so that i get a single instance of static variable.
>
> Regards
> Krishnakumar B
>
Re: Static Variables and ClassLoaders
Posted by David Jencks <da...@yahoo.com>.
Hi,
That looks to me as if it should work. Do you see the log statements
from starting the gbean? If you put log statements in your servlet
when it accesses the static instance which occurs first? You might try
logging the classloaders involved and their parentIds.
thanks
david jencks
On Sep 12, 2005, at 11:43 PM, Krishnakumar B wrote:
> Hi,
>
> Thanks for the response. I am not sure if i understood ur answer
> right. I tried the following
>
> GBean Plan Config ID = test/Hello
>
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration
> xmlns="http://geronimo.apache.org/xml/ns/deployment"
> configId="test/Hello"
> parentId="org/apache/geronimo/Server" >
> <dependency>
> <uri>test/jars/hellogbean.jar</uri>
> </dependency>
> <gbean name="HelloGBean"
> class="com.ibm.dw.reallybigpet.HelloGBean">
> </gbean>
> </configuration>
>
> Web Application Plan
>
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app
> xmlns="http://geronimo.apache.org/xml/ns/web"
> configId="test/Pet"
> parentId="test/Hello"
>>
> <context-root>/</context-root>
> <context-priority-classloader>false</context-priority-classloader>
> </web-app>
>
> I set the Parent ID of WAR plan to GBean plan Config ID. I have
> removed the dependency jar in Web Plan.
>
> Still i get a null for static reference created in GBean.
>
> Regards
> Krishnakumar B
>
>
>
> On 9/13/05, Krishnakumar B <ww...@gmail.com> wrote:
>> Hi,
>>
>> I have a doubt related to usage of Static Variables.
>>
>> "Static Variables are scoped in the class they r defined. So if a
>> class is loaded by more than one classloader in same JVM then there
>> will be multiple copies within same JVM"
>>
>> How do i used Config Id/Parent Id to ensure that 2 plans use the same
>> ClassLoader so that i get a single instance of static variable.
>>
>> Regards
>> Krishnakumar B
>>
>
Re: Static Variables and ClassLoaders
Posted by Krishnakumar B <ww...@gmail.com>.
Hi,
Thanks for the response. I am not sure if i understood ur answer
right. I tried the following
GBean Plan Config ID = test/Hello
<?xml version="1.0" encoding="UTF-8"?>
<configuration
xmlns="http://geronimo.apache.org/xml/ns/deployment"
configId="test/Hello"
parentId="org/apache/geronimo/Server" >
<dependency>
<uri>test/jars/hellogbean.jar</uri>
</dependency>
<gbean name="HelloGBean" class="com.ibm.dw.reallybigpet.HelloGBean">
</gbean>
</configuration>
Web Application Plan
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://geronimo.apache.org/xml/ns/web"
configId="test/Pet"
parentId="test/Hello"
>
<context-root>/</context-root>
<context-priority-classloader>false</context-priority-classloader>
</web-app>
I set the Parent ID of WAR plan to GBean plan Config ID. I have
removed the dependency jar in Web Plan.
Still i get a null for static reference created in GBean.
Regards
Krishnakumar B
On 9/13/05, Krishnakumar B <ww...@gmail.com> wrote:
> Hi,
>
> I have a doubt related to usage of Static Variables.
>
> "Static Variables are scoped in the class they r defined. So if a
> class is loaded by more than one classloader in same JVM then there
> will be multiple copies within same JVM"
>
> How do i used Config Id/Parent Id to ensure that 2 plans use the same
> ClassLoader so that i get a single instance of static variable.
>
> Regards
> Krishnakumar B
>