Merge branch '6.2.x'
# Conflicts: # spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
This commit is contained in:
@@ -138,8 +138,6 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
*/
|
||||
public static final String STRICT_LOCKING_PROPERTY_NAME = "spring.locking.strict";
|
||||
|
||||
private static final boolean lenientLockingAllowed = !SpringProperties.getFlag(STRICT_LOCKING_PROPERTY_NAME);
|
||||
|
||||
private static @Nullable Class<?> jakartaInjectProviderClass;
|
||||
|
||||
static {
|
||||
@@ -158,6 +156,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
private static final Map<String, Reference<DefaultListableBeanFactory>> serializableFactories =
|
||||
new ConcurrentHashMap<>(8);
|
||||
|
||||
/** Whether lenient locking is allowed in this factory. */
|
||||
private final boolean lenientLockingAllowed = !SpringProperties.getFlag(STRICT_LOCKING_PROPERTY_NAME);
|
||||
|
||||
/** Optional id for this factory, for serialization purposes. */
|
||||
private @Nullable String serializationId;
|
||||
|
||||
@@ -1035,7 +1036,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
|
||||
@Override
|
||||
protected @Nullable Boolean isCurrentThreadAllowedToHoldSingletonLock() {
|
||||
return (lenientLockingAllowed && this.preInstantiationPhase ?
|
||||
return (this.lenientLockingAllowed && this.preInstantiationPhase ?
|
||||
this.preInstantiationThread.get() != PreInstantiation.BACKGROUND : null);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,9 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
|
||||
/** Names of beans that are currently in lenient creation. */
|
||||
private final Set<String> singletonsInLenientCreation = new HashSet<>();
|
||||
|
||||
/** Map from bean name to actual creation thread for leniently created beans. */
|
||||
private final Map<String, Thread> lenientCreationThreads = new ConcurrentHashMap<>();
|
||||
|
||||
/** Flag that indicates whether we're currently within destroySingletons. */
|
||||
private volatile boolean singletonsCurrentlyInDestruction = false;
|
||||
|
||||
@@ -305,6 +308,9 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
|
||||
if (!this.singletonsInLenientCreation.contains(beanName)) {
|
||||
break;
|
||||
}
|
||||
if (this.lenientCreationThreads.get(beanName) == Thread.currentThread()) {
|
||||
throw ex;
|
||||
}
|
||||
try {
|
||||
this.lenientCreationFinished.await();
|
||||
}
|
||||
@@ -342,7 +348,18 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
|
||||
// Leniently created singleton object could have appeared in the meantime.
|
||||
singletonObject = this.singletonObjects.get(beanName);
|
||||
if (singletonObject == null) {
|
||||
singletonObject = singletonFactory.getObject();
|
||||
if (locked) {
|
||||
singletonObject = singletonFactory.getObject();
|
||||
}
|
||||
else {
|
||||
this.lenientCreationThreads.put(beanName, Thread.currentThread());
|
||||
try {
|
||||
singletonObject = singletonFactory.getObject();
|
||||
}
|
||||
finally {
|
||||
this.lenientCreationThreads.remove(beanName);
|
||||
}
|
||||
}
|
||||
newSingleton = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user