Skip to content

Commit f58854f

Browse files
committed
Locally cache factory method candidates per factory class
Issue: SPR-17071
1 parent 13873da commit f58854f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.util.HashSet;
3232
import java.util.LinkedHashSet;
3333
import java.util.List;
34-
import java.util.Map;
3534
import java.util.Set;
3635
import java.util.TreeSet;
3736
import java.util.concurrent.ConcurrentHashMap;
@@ -156,11 +155,14 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
156155
private final NamedThreadLocal<String> currentlyCreatedBean = new NamedThreadLocal<>("Currently created bean");
157156

158157
/** Cache of unfinished FactoryBean instances: FactoryBean name to BeanWrapper. */
159-
private final Map<String, BeanWrapper> factoryBeanInstanceCache = new ConcurrentHashMap<>(16);
158+
private final ConcurrentMap<String, BeanWrapper> factoryBeanInstanceCache = new ConcurrentHashMap<>();
159+
160+
/** Cache of candidate factory methods per factory class. */
161+
private final ConcurrentMap<Class<?>, Method[]> factoryMethodCandidateCache = new ConcurrentHashMap<>();
160162

161163
/** Cache of filtered PropertyDescriptors: bean Class to PropertyDescriptor array. */
162164
private final ConcurrentMap<Class<?>, PropertyDescriptor[]> filteredPropertyDescriptorsCache =
163-
new ConcurrentHashMap<>(256);
165+
new ConcurrentHashMap<>();
164166

165167

166168
/**
@@ -716,7 +718,9 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
716718
Method uniqueCandidate = null;
717719
int minNrOfArgs =
718720
(mbd.hasConstructorArgumentValues() ? mbd.getConstructorArgumentValues().getArgumentCount() : 0);
719-
Method[] candidates = ReflectionUtils.getUniqueDeclaredMethods(factoryClass);
721+
Method[] candidates = this.factoryMethodCandidateCache.computeIfAbsent(
722+
factoryClass, ReflectionUtils::getUniqueDeclaredMethods);
723+
720724
for (Method candidate : candidates) {
721725
if (Modifier.isStatic(candidate.getModifiers()) == isStatic && mbd.isFactoryMethod(candidate) &&
722726
candidate.getParameterCount() >= minNrOfArgs) {

0 commit comments

Comments
 (0)