You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by derekv <de...@yahoo.com> on 2009/05/08 19:42:43 UTC
Static member question
Lets say, i have a class in bundle "Main" that calls a method from a class
that is exported from "BundleA" and it calls the setConfiguration() method
of the javax.security.auth.login.Cofiguration. That method is static and
sets a static member. Now, lets say i have that same class in bundle "Main"
call a method from a class that is exported from "BundleB" and that method
also calls the setConfiguration() method. Will i have two instances of the
same singleton because the caller is in two different bundles? or will i
have one instance because they are both called from the bundle "Main"???
// Main bundle
class Main {
public void someMethod() {
servicea.methodA();
serviceb.methodB();
}
}
// BundleA
import javax.security.auth.login.*;
class Servicea {
public void methodA() {
Configuration.setConfiguration(a);
}
}
// BundleB
import javax.security.auth.login.*;
class Serviceb {
public void methodB() {
Configuration.setConfiguration(b);
}
}
--
View this message in context: http://www.nabble.com/Static-member-question-tp23450349p23450349.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
RE: Static member question
Posted by Sergey Shcherbakov <ss...@echelon.de>.
Hello everybody,
Recently embedding Felix (Karaf) I ran into the exactly same issue:
http://www.mail-archive.com/dev@felix.apache.org/msg04908.html
While the solution with setting TCL to null works I was wondering
whether this solution remains recommended one?
The issue looks to be fixed also by setting log4j.ignoreTCL=true in the
system/config properties.
Best Regards,
Sergey Shcherbakov.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Static member question
Posted by Rob Walker <ro...@ascert.com>.
Just to expand on Richard's explanation a little -
* statics are global within the scope of their classloader
So as Richard says, in your case since the class was loaded by one
classloader, you'll still have a singleton across your JVM
In a case where the same class appears in different bundles, and is
loaded locally by that bundle's classloader (e.g. neither class is
resolved to the other by imports/exports) then any statics in that class
will not be singletons in terms of the whole JVM - they'll only have
singleton scope for their bundle.
-- Rob
Richard S. Hall wrote:
> There is only one singleton because there is only one copy of the
> Configuration class in BundleA...assuming both Main and BundleB both
> import javax.security.auth.login (i.e., they don't have a private copy
> in their bundle) and they are both wired to the same provider of the
> package.
>
> -> richard
>
> On 5/8/09 1:42 PM, derekv wrote:
>> Lets say, i have a class in bundle "Main" that calls a method from a
>> class
>> that is exported from "BundleA" and it calls the setConfiguration()
>> method
>> of the javax.security.auth.login.Cofiguration. That method is static and
>> sets a static member. Now, lets say i have that same class in bundle
>> "Main"
>> call a method from a class that is exported from "BundleB" and that
>> method
>> also calls the setConfiguration() method. Will i have two instances
>> of the
>> same singleton because the caller is in two different bundles? or will i
>> have one instance because they are both called from the bundle "Main"???
>>
>> // Main bundle
>> class Main {
>> public void someMethod() {
>> servicea.methodA();
>> serviceb.methodB();
>> }
>> }
>>
>> // BundleA
>> import javax.security.auth.login.*;
>> class Servicea {
>> public void methodA() {
>> Configuration.setConfiguration(a);
>> }
>> }
>>
>> // BundleB
>> import javax.security.auth.login.*;
>> class Serviceb {
>> public void methodB() {
>> Configuration.setConfiguration(b);
>> }
>> }
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
--
Ascert - Taking systems to the Edge
robw@ascert.com
+44 (0)20 7488 3470
www.ascert.com
Re: Static member question
Posted by "Richard S. Hall" <he...@ungoverned.org>.
There is only one singleton because there is only one copy of the
Configuration class in BundleA...assuming both Main and BundleB both
import javax.security.auth.login (i.e., they don't have a private copy
in their bundle) and they are both wired to the same provider of the
package.
-> richard
On 5/8/09 1:42 PM, derekv wrote:
> Lets say, i have a class in bundle "Main" that calls a method from a class
> that is exported from "BundleA" and it calls the setConfiguration() method
> of the javax.security.auth.login.Cofiguration. That method is static and
> sets a static member. Now, lets say i have that same class in bundle "Main"
> call a method from a class that is exported from "BundleB" and that method
> also calls the setConfiguration() method. Will i have two instances of the
> same singleton because the caller is in two different bundles? or will i
> have one instance because they are both called from the bundle "Main"???
>
> // Main bundle
> class Main {
> public void someMethod() {
> servicea.methodA();
> serviceb.methodB();
> }
> }
>
> // BundleA
> import javax.security.auth.login.*;
> class Servicea {
> public void methodA() {
> Configuration.setConfiguration(a);
> }
> }
>
> // BundleB
> import javax.security.auth.login.*;
> class Serviceb {
> public void methodB() {
> Configuration.setConfiguration(b);
> }
> }
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org