}
public Object instance() {
Object singletonInstancePerThread = null;
// use weak reference to prevent cyclic reference during GC
WeakReference ref = (WeakReference) perThreadCache.get();
// singletonInstancePerThread=perThreadCache.get();
// if (singletonInstancePerThread==null) {
if (ref == null || ref.get() == null) {
Class clazz = null;
try {
clazz = Thread.currentThread().getContextClassLoader().loadClass(
singletonClassName);
singletonInstancePerThread = clazz.newInstance();
} catch (Exception ignore) {
try {
clazz = Class.forName(singletonClassName);
singletonInstancePerThread = clazz.newInstance();
} catch (Exception ignore2) {
}
}
perThreadCache.set(new WeakReference(singletonInstancePerThread));
} else {
singletonInstancePerThread = ref.get();
}
return singletonInstancePerThread;
}