Keep mainThreadPrefix exposed until background init threads finished

Closes gh-35409
This commit is contained in:
Juergen Hoeller 2025-09-03 15:45:12 +02:00
parent 33fe8d29c1
commit 3a4315bf16
1 changed files with 9 additions and 11 deletions

View File

@ -1113,11 +1113,10 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
List<String> beanNames = new ArrayList<>(this.beanDefinitionNames); List<String> beanNames = new ArrayList<>(this.beanDefinitionNames);
// Trigger initialization of all non-lazy singleton beans... // Trigger initialization of all non-lazy singleton beans...
List<CompletableFuture<?>> futures = new ArrayList<>();
this.preInstantiationThread.set(PreInstantiation.MAIN); this.preInstantiationThread.set(PreInstantiation.MAIN);
this.mainThreadPrefix = getThreadNamePrefix(); this.mainThreadPrefix = getThreadNamePrefix();
try { try {
List<CompletableFuture<?>> futures = new ArrayList<>();
for (String beanName : beanNames) { for (String beanName : beanNames) {
RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName); RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
if (!mbd.isAbstract() && mbd.isSingleton()) { if (!mbd.isAbstract() && mbd.isSingleton()) {
@ -1127,12 +1126,6 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
} }
} }
} }
}
finally {
this.mainThreadPrefix = null;
this.preInstantiationThread.remove();
}
if (!futures.isEmpty()) { if (!futures.isEmpty()) {
try { try {
CompletableFuture.allOf(futures.toArray(new CompletableFuture<?>[0])).join(); CompletableFuture.allOf(futures.toArray(new CompletableFuture<?>[0])).join();
@ -1141,6 +1134,11 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
ReflectionUtils.rethrowRuntimeException(ex.getCause()); ReflectionUtils.rethrowRuntimeException(ex.getCause());
} }
} }
}
finally {
this.mainThreadPrefix = null;
this.preInstantiationThread.remove();
}
// Trigger post-initialization callback for all applicable beans... // Trigger post-initialization callback for all applicable beans...
for (String beanName : beanNames) { for (String beanName : beanNames) {