|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.backsource.utils.lang.ClassContextLocal
The classloader equivalent of ThreadLocal.
This class provides class context variable. This means that it is possible to get a static variable to only be visable in the context class loader, which is verry usefull to get Singleton behaviour without the static variable beeing propagated to the complete JVM.
It is modelled after the ThreadLocal class, and the same
limitations is valid: only threads executing in the same context
classloader that set a value will be able to se the value. See
InheritableClassContextLocal and FindClassContextLocal for other cinds of behaviour.
Example. You want a singleton, but it must only be valid (set) in a single component, but you can not guarantee that the singleton class will not be loaded i a parent (global) classloader.
If you however know that at least your component will be executing in its own context classloader you may use this class, much like using a ThreadLocal.
Just a demo, set singleton up. Will onlye be available in current context classloader, even thoug the instance variable is static
class MySingleton {
static ClassContextLocal instance = new ClassContextLocal();
public static void configure(Properties prop) {
MySingleton s = new MySingleton();
s.configure(prop);
instance.set(s);
}
public static MySingleton getInstance() {
return instance.get();
}
protected MySingleton() {
}
protected void configure(Properties prop) {
//Configure it here
}
}
| Field Summary | |
protected java.util.Map |
map
|
| Constructor Summary | |
ClassContextLocal()
|
|
| Method Summary | |
java.lang.Object |
get()
Get value from current context class loader. |
void |
set(java.lang.Object object)
Set value in current context class loader. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected java.util.Map map
| Constructor Detail |
public ClassContextLocal()
| Method Detail |
public java.lang.Object get()
public void set(java.lang.Object object)
object - save object in current classloader.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||