Enforce circular reference exception between more than two threads as well
See gh-34672
This commit is contained in:
@@ -315,7 +315,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
|
||||
while ((singletonObject = this.singletonObjects.get(beanName)) == null) {
|
||||
Thread otherThread = this.currentCreationThreads.get(beanName);
|
||||
if (otherThread != null && (otherThread == currentThread ||
|
||||
this.lenientWaitingThreads.get(otherThread) == currentThread)) {
|
||||
checkDependentWaitingThreads(otherThread, currentThread))) {
|
||||
throw ex;
|
||||
}
|
||||
if (!this.singletonsInLenientCreation.contains(beanName)) {
|
||||
@@ -431,6 +431,16 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkDependentWaitingThreads(Thread waitingThread, Thread candidateThread) {
|
||||
Thread threadToCheck = waitingThread;
|
||||
while ((threadToCheck = this.lenientWaitingThreads.get(threadToCheck)) != null) {
|
||||
if (threadToCheck == candidateThread) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the current thread is allowed to hold the singleton lock.
|
||||
* <p>By default, any thread may acquire and hold the singleton lock, except
|
||||
|
||||
Reference in New Issue
Block a user