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: [email protected]
For additional commands, e-mail: [email protected]
--
Ascert - Taking systems to the Edge
[email protected]
+44 (0)20 7488 3470
www.ascert.com