@@ -1099,11 +1099,10 @@ public void preInstantiateSingletons() throws BeansException {
10991099List <String > beanNames = new ArrayList <>(this .beanDefinitionNames );
11001100
11011101// Trigger initialization of all non-lazy singleton beans...
1102- List <CompletableFuture <?>> futures = new ArrayList <>();
1103-
11041102this .preInstantiationThread .set (PreInstantiation .MAIN );
11051103this .mainThreadPrefix = getThreadNamePrefix ();
11061104try {
1105+ List <CompletableFuture <?>> futures = new ArrayList <>();
11071106for (String beanName : beanNames ) {
11081107RootBeanDefinition mbd = getMergedLocalBeanDefinition (beanName );
11091108if (!mbd .isAbstract () && mbd .isSingleton ()) {
@@ -1113,21 +1112,20 @@ public void preInstantiateSingletons() throws BeansException {
11131112}
11141113}
11151114}
1115+ if (!futures .isEmpty ()) {
1116+ try {
1117+ CompletableFuture .allOf (futures .toArray (new CompletableFuture <?>[0 ])).join ();
1118+ }
1119+ catch (CompletionException ex ) {
1120+ ReflectionUtils .rethrowRuntimeException (ex .getCause ());
1121+ }
1122+ }
11161123}
11171124finally {
11181125this .mainThreadPrefix = null ;
11191126this .preInstantiationThread .remove ();
11201127}
11211128
1122- if (!futures .isEmpty ()) {
1123- try {
1124- CompletableFuture .allOf (futures .toArray (new CompletableFuture <?>[0 ])).join ();
1125- }
1126- catch (CompletionException ex ) {
1127- ReflectionUtils .rethrowRuntimeException (ex .getCause ());
1128- }
1129- }
1130-
11311129// Trigger post-initialization callback for all applicable beans...
11321130for (String beanName : beanNames ) {
11331131Object singletonInstance = getSingleton (beanName , false );
0 commit comments