Skip to content

Commit a403a75

Browse files
committed
BeanFactoryAdvisorRetrievalHelper avoids synchronization for name cache
Issue: SPR-16570
1 parent 2ae2249 commit a403a75

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ public class ProxyCreatorSupport extends AdvisedSupport {
3434

3535
private AopProxyFactory aopProxyFactory;
3636

37-
private List<AdvisedSupportListener> listeners = new LinkedList<AdvisedSupportListener>();
37+
private final List<AdvisedSupportListener> listeners = new LinkedList<AdvisedSupportListener>();
3838

3939
/** Set to true when the first AOP proxy has been created */
4040
private boolean active = false;

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.aop.framework.autoproxy;
1818

19-
import java.util.LinkedList;
19+
import java.util.ArrayList;
2020
import java.util.List;
2121

2222
import org.apache.commons.logging.Log;
@@ -43,7 +43,7 @@ public class BeanFactoryAdvisorRetrievalHelper {
4343

4444
private final ConfigurableListableBeanFactory beanFactory;
4545

46-
private String[] cachedAdvisorBeanNames;
46+
private volatile String[] cachedAdvisorBeanNames;
4747

4848

4949
/**
@@ -64,22 +64,19 @@ public BeanFactoryAdvisorRetrievalHelper(ConfigurableListableBeanFactory beanFac
6464
*/
6565
public List<Advisor> findAdvisorBeans() {
6666
// Determine list of advisor bean names, if not cached already.
67-
String[] advisorNames = null;
68-
synchronized (this) {
69-
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;
76-
}
67+
String[] advisorNames = this.cachedAdvisorBeanNames;
68+
if (advisorNames == null) {
69+
// Do not initialize FactoryBeans here: We need to leave all regular beans
70+
// uninitialized to let the auto-proxy creator apply to them!
71+
advisorNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
72+
this.beanFactory, Advisor.class, true, false);
73+
this.cachedAdvisorBeanNames = advisorNames;
7774
}
7875
if (advisorNames.length == 0) {
79-
return new LinkedList<Advisor>();
76+
return new ArrayList<Advisor>();
8077
}
8178

82-
List<Advisor> advisors = new LinkedList<Advisor>();
79+
List<Advisor> advisors = new ArrayList<Advisor>();
8380
for (String name : advisorNames) {
8481
if (isEligibleBean(name)) {
8582
if (this.beanFactory.isCurrentlyInCreation(name)) {

0 commit comments

Comments
 (0)