mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Perform initialization in foreground if BackgroundPreinitializer fails
Google App Engine probits the creation of new threads. This leads to a failure in BackgroundPreinitializer when the single thread executor attempts to create its single thread. This commit enhances the existing fail safety of BackgroundPreinitializer by catching any exceptions thrown while creating the executor and submitting the tasks to it. Any initialisation that has not performed in the background will be performed in the foreground instead. Closes gh-4662
This commit is contained in:
parent
da50eb9ab2
commit
bcaee0ebee
@ -39,11 +39,18 @@ public class BackgroundPreinitializer
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationStartedEvent event) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
submit(executor, new MessageConverterInitializer());
|
||||
submit(executor, new MBeanFactoryInitializer());
|
||||
submit(executor, new ValidationInitializer());
|
||||
executor.shutdown();
|
||||
try {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
submit(executor, new MessageConverterInitializer());
|
||||
submit(executor, new MBeanFactoryInitializer());
|
||||
submit(executor, new ValidationInitializer());
|
||||
executor.shutdown();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// This will fail on GAE where creating threads is prohibited. We can safely
|
||||
// continue but startup will be slightly slower as the initialization will now
|
||||
// happen on the main thread.
|
||||
}
|
||||
}
|
||||
|
||||
private void submit(ExecutorService executor, Runnable runnable) {
|
||||
|
Loading…
Reference in New Issue
Block a user