BeanIdentifier id = getId(contextual);
ContextualInstance<T> beanInstance = beanStore.get(id);
if (beanInstance != null) {
return beanInstance.getInstance();
} else if (creationalContext != null) {
LockedBean lock = null;
try {
if (multithreaded) {
lock = beanStore.lock(id);
beanInstance = beanStore.get(id);
if (beanInstance != null) {
return beanInstance.getInstance();
}
}
T instance = contextual.create(creationalContext);
if (instance != null) {
beanInstance = new SerializableContextualInstanceImpl<Contextual<T>, T>(contextual, instance, creationalContext, serviceRegistry.get(ContextualStore.class));
getBeanStore().put(id, beanInstance);
}
return instance;
} finally {
if (lock != null) {
lock.unlock();
}
}
} else {
return null;
}