From c24825ca195a4d4eeb642d603b1db62639cf0024 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 8 Nov 2012 23:15:38 +0100 Subject: [PATCH] DefaultSingletonBeanRegistry avoids singletonObjects lock wherever possible for non-singleton factory performance Issue: SPR-9819 --- .../beans/factory/support/DefaultSingletonBeanRegistry.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java index d4a0bacecf8..67b3841eb24 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java @@ -166,7 +166,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements } public Object getSingleton(String beanName) { - return getSingleton(beanName, true); + return getSingleton(beanName, isSingletonCurrentlyInCreation(beanName)); } /** @@ -179,10 +179,10 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements */ protected Object getSingleton(String beanName, boolean allowEarlyReference) { Object singletonObject = this.singletonObjects.get(beanName); - if (singletonObject == null) { + if (singletonObject == null && allowEarlyReference) { synchronized (this.singletonObjects) { singletonObject = this.earlySingletonObjects.get(beanName); - if (singletonObject == null && allowEarlyReference) { + if (singletonObject == null) { ObjectFactory singletonFactory = this.singletonFactories.get(beanName); if (singletonFactory != null) { singletonObject = singletonFactory.getObject();