Skip to content

Commit 7f1a8d7

Browse files
committed
BeanFactoryAdvisorRetrievalHelper avoids synchronization for name cache
Issue: SPR-16570
1 parent 47d8fe8 commit 7f1a8d7

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class BeanFactoryAdvisorRetrievalHelper {
4545
private final ConfigurableListableBeanFactory beanFactory;
4646

4747
@Nullable
48-
private String[] cachedAdvisorBeanNames;
48+
private volatile String[] cachedAdvisorBeanNames;
4949

5050

5151
/**
@@ -66,16 +66,13 @@ public BeanFactoryAdvisorRetrievalHelper(ConfigurableListableBeanFactory beanFac
6666
*/
6767
public List<Advisor> findAdvisorBeans() {
6868
// Determine list of advisor bean names, if not cached already.
69-
String[] advisorNames = null;
70-
synchronized (this) {
71-
advisorNames = this.cachedAdvisorBeanNames;
72-
if (advisorNames == null) {
73-
// Do not initialize FactoryBeans here: We need to leave all regular beans
74-
// uninitialized to let the auto-proxy creator apply to them!
75-
advisorNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
76-
this.beanFactory, Advisor.class, true, false);
77-
this.cachedAdvisorBeanNames = advisorNames;
78-
}
69+
String[] advisorNames = this.cachedAdvisorBeanNames;
70+
if (advisorNames == null) {
71+
// Do not initialize FactoryBeans here: We need to leave all regular beans
72+
// uninitialized to let the auto-proxy creator apply to them!
73+
advisorNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
74+
this.beanFactory, Advisor.class, true, false);
75+
this.cachedAdvisorBeanNames = advisorNames;
7976
}
8077
if (advisorNames.length == 0) {
8178
return new ArrayList<>();

0 commit comments

Comments
 (0)