@@ -1113,11 +1113,10 @@ public void preInstantiateSingletons() throws BeansException {
11131113 List <String > beanNames = new ArrayList <>(this .beanDefinitionNames );
11141114
11151115 // Trigger initialization of all non-lazy singleton beans...
1116- List <CompletableFuture <?>> futures = new ArrayList <>();
1117-
11181116 this .preInstantiationThread .set (PreInstantiation .MAIN );
11191117 this .mainThreadPrefix = getThreadNamePrefix ();
11201118 try {
1119+ List <CompletableFuture <?>> futures = new ArrayList <>();
11211120 for (String beanName : beanNames ) {
11221121 RootBeanDefinition mbd = getMergedLocalBeanDefinition (beanName );
11231122 if (!mbd .isAbstract () && mbd .isSingleton ()) {
@@ -1127,21 +1126,20 @@ public void preInstantiateSingletons() throws BeansException {
11271126 }
11281127 }
11291128 }
1129+ if (!futures .isEmpty ()) {
1130+ try {
1131+ CompletableFuture .allOf (futures .toArray (new CompletableFuture <?>[0 ])).join ();
1132+ }
1133+ catch (CompletionException ex ) {
1134+ ReflectionUtils .rethrowRuntimeException (ex .getCause ());
1135+ }
1136+ }
11301137 }
11311138 finally {
11321139 this .mainThreadPrefix = null ;
11331140 this .preInstantiationThread .remove ();
11341141 }
11351142
1136- if (!futures .isEmpty ()) {
1137- try {
1138- CompletableFuture .allOf (futures .toArray (new CompletableFuture <?>[0 ])).join ();
1139- }
1140- catch (CompletionException ex ) {
1141- ReflectionUtils .rethrowRuntimeException (ex .getCause ());
1142- }
1143- }
1144-
11451143 // Trigger post-initialization callback for all applicable beans...
11461144 for (String beanName : beanNames ) {
11471145 Object singletonInstance = getSingleton (beanName , false );
0 commit comments