geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <>
Subject Re: SOS! static variable not work under 2.0.2 !!
Date Fri, 19 Sep 2008 15:47:40 GMT

On Sep 19, 2008, at 2:44 AM, Y.H. wrote:

> Dear sir,
>  Whatever using singleton pattern or static variable, Geronimo could  
> not
> access correctly like static variable or singleton behavior!
>  1. I just used a Class which declaired a public static String  
> public class TestClass{
>  public static String STATICDATA;
> }
> 2. a AServlet in AWeb application: TestClass.STATICDATA="abc"; the in
> BServlet in AWeb application can get "abc" from TestClass.STATICDATA.
> 3. BUT, a CServlet in BWeb application tried to get value from
> TestClass.STATICDATA. the result is null
> GOD! everything will be ok in WebSphere/Tomcat/WebLog, but just  
> Geronimo
> not.
> Any help will be appreciated.

I'm extremely surprised that this works in any app server other than  
jboss unless you deploy your singleton class to a shared classloader  
such as a "lib" directory of the server.  Use of singletons in javaee  
apps is strongly frowned upon because they are not supposed to work  
between applications -- separate applications are supposed to have  
separate classloaders, resulting in separate copies of the singleton  
class, and the behavior you are seeing.

In geronimo there are a lot of options for getting only one copy of  
the singleton class, if that is what you want:

-- easiest is to make one web application depend on the other one.   
When you deploy AWeb, geronimo will tell you the configID of the  
resulting plugin/module/classloader.  List this as a dependency in the  
geronimo plan for BWeb.
Otherwise you will need to package the singleton class separately from  
the web apps and either:

-- put the jar in shared/lib and include a dependency on the shared  
classloader in each web app (the existence of the shared classloader  
is a nasty hack IMO)
-- put the jar in an appropriate place in the geronimo repository,  
construct a service module depending on this jar, and have each web  
app depend on this service module.  We do this in geronimo in a few  
places for e.g. the javaee specs.

Having one app depend on the other will probably work fine for you.   
BTW, I think you need to make the variable volatile or synchronize  
access to it to avoid problems with thread safety.

david jencks

> -- 
> View this message in context:
> Sent from the Apache Geronimo - Users mailing list archive at  

View raw message