public class PerThreadSingleton<T> extends java.lang.Object implements SingletonStrategy<T>
PerThreadSingleton
is an implementation of the
SingletonStrategy used to provide common factory access to a single object
instance based on an implementation strategy for one object instance per
thread. This is useful in replace of the ThreadLocal usage.
Modifier and Type | Field and Description |
---|---|
private java.lang.ThreadLocal<java.lang.ref.WeakReference<T>> |
perThreadCache |
private java.lang.String |
singletonClassName |
Constructor and Description |
---|
PerThreadSingleton() |
Modifier and Type | Method and Description |
---|---|
T |
instance() |
void |
reset()
reset the instance to a new instance for the implemented strategy
|
void |
setSingletonClassName(java.lang.String singletonClassName)
set a singleton class name that will be used to create the singleton
based on the strategy implementation of this interface.
|
private java.lang.String singletonClassName
private java.lang.ThreadLocal<java.lang.ref.WeakReference<T>> perThreadCache
public void reset()
SingletonStrategy
reset
in interface SingletonStrategy<T>
public T instance()
instance
in interface SingletonStrategy<T>
public void setSingletonClassName(java.lang.String singletonClassName)
SingletonStrategy
setSingletonClassName
in interface SingletonStrategy<T>
singletonClassName
- DOCUMENT ME!