Locally cache factory method candidates per factory class

Issue: SPR-17071
This commit is contained in:
Juergen Hoeller 2018-07-22 19:22:20 +02:00
parent 13873dafb7
commit f58854f4b9
1 changed files with 8 additions and 4 deletions

View File

@ -31,7 +31,6 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
@ -156,11 +155,14 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
private final NamedThreadLocal<String> currentlyCreatedBean = new NamedThreadLocal<>("Currently created bean");
/** Cache of unfinished FactoryBean instances: FactoryBean name to BeanWrapper. */
private final Map<String, BeanWrapper> factoryBeanInstanceCache = new ConcurrentHashMap<>(16);
private final ConcurrentMap<String, BeanWrapper> factoryBeanInstanceCache = new ConcurrentHashMap<>();
/** Cache of candidate factory methods per factory class. */
private final ConcurrentMap<Class<?>, Method[]> factoryMethodCandidateCache = new ConcurrentHashMap<>();
/** Cache of filtered PropertyDescriptors: bean Class to PropertyDescriptor array. */
private final ConcurrentMap<Class<?>, PropertyDescriptor[]> filteredPropertyDescriptorsCache =
new ConcurrentHashMap<>(256);
new ConcurrentHashMap<>();
/**
@ -716,7 +718,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
Method uniqueCandidate = null;
int minNrOfArgs =
(mbd.hasConstructorArgumentValues() ? mbd.getConstructorArgumentValues().getArgumentCount() : 0);
Method[] candidates = ReflectionUtils.getUniqueDeclaredMethods(factoryClass);
Method[] candidates = this.factoryMethodCandidateCache.computeIfAbsent(
factoryClass, ReflectionUtils::getUniqueDeclaredMethods);
for (Method candidate : candidates) {
if (Modifier.isStatic(candidate.getModifiers()) == isStatic && mbd.isFactoryMethod(candidate) &&
candidate.getParameterCount() >= minNrOfArgs) {