Skip to content

Commit 1841ad3

Browse files
committed
Consistently use local copy of volatile mainThreadPrefix field
Closes gh-34746
1 parent 0477ba4 commit 1841ad3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -1066,8 +1066,9 @@ protected void checkMergedBeanDefinition(RootBeanDefinition mbd, String beanName
10661066
@Nullable
10671067
protected Boolean isCurrentThreadAllowedToHoldSingletonLock() {
10681068
String mainThreadPrefix = this.mainThreadPrefix;
1069-
if (this.mainThreadPrefix != null) {
1070-
// We only differentiate in the preInstantiateSingletons phase.
1069+
if (mainThreadPrefix != null) {
1070+
// We only differentiate in the preInstantiateSingletons phase, using
1071+
// the volatile mainThreadPrefix field as an indicator for that phase.
10711072

10721073
PreInstantiation preInstantiation = this.preInstantiationThread.get();
10731074
if (preInstantiation != null) {
@@ -1087,7 +1088,7 @@ protected Boolean isCurrentThreadAllowedToHoldSingletonLock() {
10871088
}
10881089
else if (this.strictLocking == null) {
10891090
// No explicit locking configuration -> infer appropriate locking.
1090-
if (mainThreadPrefix != null && !getThreadNamePrefix().equals(mainThreadPrefix)) {
1091+
if (!getThreadNamePrefix().equals(mainThreadPrefix)) {
10911092
// An unmanaged thread (assumed to be application-internal) with lenient locking,
10921093
// and not part of the same thread pool that provided the main bootstrap thread
10931094
// (excluding scenarios where we are hit by multiple external bootstrap threads).

0 commit comments

Comments
 (0)