From 8eac87064dd0d0884b830be68e2a6921f10bfede Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 21 Aug 2014 14:26:17 +0200 Subject: [PATCH] AbstractAutowireCapableBeanFactory avoids synchronization in filterPropertyDescriptorsForDependencyCheck Issue: SPR-12106 --- .../AbstractAutowireCapableBeanFactory.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java index 2b4e4eb33a..2423b1230e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java @@ -37,6 +37,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanWrapper; @@ -148,7 +149,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac new ConcurrentHashMap(16); /** Cache of filtered PropertyDescriptors: bean Class -> PropertyDescriptor array */ - private final Map, PropertyDescriptor[]> filteredPropertyDescriptorsCache = + private final ConcurrentMap, PropertyDescriptor[]> filteredPropertyDescriptorsCache = new ConcurrentHashMap, PropertyDescriptor[]>(64); @@ -1315,18 +1316,14 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac protected PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck(BeanWrapper bw, boolean cache) { PropertyDescriptor[] filtered = this.filteredPropertyDescriptorsCache.get(bw.getWrappedClass()); if (filtered == null) { + filtered = filterPropertyDescriptorsForDependencyCheck(bw); if (cache) { - synchronized (this.filteredPropertyDescriptorsCache) { - filtered = this.filteredPropertyDescriptorsCache.get(bw.getWrappedClass()); - if (filtered == null) { - filtered = filterPropertyDescriptorsForDependencyCheck(bw); - this.filteredPropertyDescriptorsCache.put(bw.getWrappedClass(), filtered); - } + PropertyDescriptor[] existing = + this.filteredPropertyDescriptorsCache.putIfAbsent(bw.getWrappedClass(), filtered); + if (existing != null) { + filtered = existing; } } - else { - filtered = filterPropertyDescriptorsForDependencyCheck(bw); - } } return filtered; }