From a9f28575b13d8adf1f7bab92f84c96ad471f7159 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 20 Oct 2011 12:06:40 +0000 Subject: [PATCH] optimized DefaultListableBeanFactory's PropertyDescriptor caching for concurrent access (SPR-7863) --- .../AbstractAutowireCapableBeanFactory.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java index efe8e7a21b..e53e5cf504 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java @@ -28,7 +28,6 @@ import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; @@ -144,7 +143,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac /** Cache of filtered PropertyDescriptors: bean Class -> PropertyDescriptor array */ private final Map filteredPropertyDescriptorsCache = - new HashMap(); + new ConcurrentHashMap(); /** @@ -1201,22 +1200,25 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @see #isExcludedFromDependencyCheck */ protected PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck(BeanWrapper bw) { - synchronized (this.filteredPropertyDescriptorsCache) { - PropertyDescriptor[] filtered = this.filteredPropertyDescriptorsCache.get(bw.getWrappedClass()); - if (filtered == null) { - List pds = - new LinkedList(Arrays.asList(bw.getPropertyDescriptors())); - for (Iterator it = pds.iterator(); it.hasNext();) { - PropertyDescriptor pd = it.next(); - if (isExcludedFromDependencyCheck(pd)) { - it.remove(); + PropertyDescriptor[] filtered = this.filteredPropertyDescriptorsCache.get(bw.getWrappedClass()); + if (filtered == null) { + synchronized (this.filteredPropertyDescriptorsCache) { + filtered = this.filteredPropertyDescriptorsCache.get(bw.getWrappedClass()); + if (filtered == null) { + List pds = + new LinkedList(Arrays.asList(bw.getPropertyDescriptors())); + for (Iterator it = pds.iterator(); it.hasNext();) { + PropertyDescriptor pd = it.next(); + if (isExcludedFromDependencyCheck(pd)) { + it.remove(); + } } + filtered = pds.toArray(new PropertyDescriptor[pds.size()]); + this.filteredPropertyDescriptorsCache.put(bw.getWrappedClass(), filtered); } - filtered = pds.toArray(new PropertyDescriptor[pds.size()]); - this.filteredPropertyDescriptorsCache.put(bw.getWrappedClass(), filtered); } - return filtered; } + return filtered; } /**