On Aug 27, 2011, at 1:59 PM, DonLuigi wrote:

> 
> Jean-Baptiste Onofré wrote:
>> 
>> you are right, for instance a singleton (static) is local to one 
>> classloader.
>> 
> 
> Please let me clarify - in my test when I use Import-Package, several
> bundles see the same static variable, exported by common bundle. When one
> bundle changes static value, all other bundles see the change.
> 
> Is this expected behaviour or am I doing something wrong?

This is expected.

> Shouldn't each
> bundle load and initialize its own copy of imported class?

No.

I think the kind of behavior you want can be found in service factories.  When 
you register a service using a service factory, each requesting bundle gets 
it's own copy of the service object.  So you could use a non-static property in 
a service set up as a service factory.  Since only one copy of the class is 
loaded, any static variable will be shared among all service instances.

thanks
david jencks

> 
> Thanks,
> Ludvik
> 
> --
> View this message in context: 
> http://karaf.922171.n3.nabble.com/Static-variables-tp3287037p3289607.html
> Sent from the Karaf - User mailing list archive at Nabble.com.

Reply via email to