Skip to content

Commit 8eac870

Browse files
committed
AbstractAutowireCapableBeanFactory avoids synchronization in filterPropertyDescriptorsForDependencyCheck
Issue: SPR-12106
1 parent a000dd7 commit 8eac870

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Set;
3838
import java.util.TreeSet;
3939
import java.util.concurrent.ConcurrentHashMap;
40+
import java.util.concurrent.ConcurrentMap;
4041

4142
import org.springframework.beans.BeanUtils;
4243
import org.springframework.beans.BeanWrapper;
@@ -148,7 +149,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
148149
new ConcurrentHashMap<String, BeanWrapper>(16);
149150

150151
/** Cache of filtered PropertyDescriptors: bean Class -> PropertyDescriptor array */
151-
private final Map<Class<?>, PropertyDescriptor[]> filteredPropertyDescriptorsCache =
152+
private final ConcurrentMap<Class<?>, PropertyDescriptor[]> filteredPropertyDescriptorsCache =
152153
new ConcurrentHashMap<Class<?>, PropertyDescriptor[]>(64);
153154

154155

@@ -1315,18 +1316,14 @@ protected String[] unsatisfiedNonSimpleProperties(AbstractBeanDefinition mbd, Be
13151316
protected PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck(BeanWrapper bw, boolean cache) {
13161317
PropertyDescriptor[] filtered = this.filteredPropertyDescriptorsCache.get(bw.getWrappedClass());
13171318
if (filtered == null) {
1319+
filtered = filterPropertyDescriptorsForDependencyCheck(bw);
13181320
if (cache) {
1319-
synchronized (this.filteredPropertyDescriptorsCache) {
1320-
filtered = this.filteredPropertyDescriptorsCache.get(bw.getWrappedClass());
1321-
if (filtered == null) {
1322-
filtered = filterPropertyDescriptorsForDependencyCheck(bw);
1323-
this.filteredPropertyDescriptorsCache.put(bw.getWrappedClass(), filtered);
1324-
}
1321+
PropertyDescriptor[] existing =
1322+
this.filteredPropertyDescriptorsCache.putIfAbsent(bw.getWrappedClass(), filtered);
1323+
if (existing != null) {
1324+
filtered = existing;
13251325
}
13261326
}
1327-
else {
1328-
filtered = filterPropertyDescriptorsForDependencyCheck(bw);
1329-
}
13301327
}
13311328
return filtered;
13321329
}

0 commit comments

Comments
 (0)