|
|
@ -20,11 +20,9 @@ import javax.validation.Validation;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.catalina.mbeans.MBeanFactory;
|
|
|
|
import org.apache.catalina.mbeans.MBeanFactory;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
|
|
|
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
|
|
|
import org.springframework.boot.logging.LoggingApplicationListener;
|
|
|
|
import org.springframework.boot.logging.LoggingApplicationListener;
|
|
|
|
import org.springframework.context.ApplicationEvent;
|
|
|
|
|
|
|
|
import org.springframework.context.ApplicationListener;
|
|
|
|
import org.springframework.context.ApplicationListener;
|
|
|
|
import org.springframework.context.event.ContextRefreshedEvent;
|
|
|
|
|
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
|
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
|
|
|
|
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
|
|
|
|
|
|
|
|
|
|
|
@ -37,21 +35,11 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage
|
|
|
|
* @since 1.3.0
|
|
|
|
* @since 1.3.0
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Order(LoggingApplicationListener.DEFAULT_ORDER + 1)
|
|
|
|
@Order(LoggingApplicationListener.DEFAULT_ORDER + 1)
|
|
|
|
public class BackgroundPreinitializer implements ApplicationListener<ApplicationEvent> {
|
|
|
|
public class BackgroundPreinitializer
|
|
|
|
|
|
|
|
implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
|
|
|
|
private volatile Thread initializationThread;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onApplicationEvent(ApplicationEvent event) {
|
|
|
|
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
|
|
|
|
if (event instanceof ApplicationStartedEvent) {
|
|
|
|
|
|
|
|
performInitialization();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (event instanceof ContextRefreshedEvent) {
|
|
|
|
|
|
|
|
awaitInitialization();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void performInitialization() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Thread thread = new Thread(new Runnable() {
|
|
|
|
Thread thread = new Thread(new Runnable() {
|
|
|
|
|
|
|
|
|
|
|
@ -73,7 +61,6 @@ public class BackgroundPreinitializer implements ApplicationListener<Application
|
|
|
|
|
|
|
|
|
|
|
|
}, "background-preinit");
|
|
|
|
}, "background-preinit");
|
|
|
|
thread.start();
|
|
|
|
thread.start();
|
|
|
|
this.initializationThread = thread;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
catch (Exception ex) {
|
|
|
|
// This will fail on GAE where creating threads is prohibited. We can safely
|
|
|
|
// This will fail on GAE where creating threads is prohibited. We can safely
|
|
|
@ -82,21 +69,6 @@ public class BackgroundPreinitializer implements ApplicationListener<Application
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void awaitInitialization() {
|
|
|
|
|
|
|
|
Thread thread = this.initializationThread;
|
|
|
|
|
|
|
|
if (thread != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
thread.join();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (InterruptedException ex) {
|
|
|
|
|
|
|
|
Thread.currentThread().interrupt();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
finally {
|
|
|
|
|
|
|
|
this.initializationThread = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Early initializer for Spring MessageConverters.
|
|
|
|
* Early initializer for Spring MessageConverters.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -132,4 +104,5 @@ public class BackgroundPreinitializer implements ApplicationListener<Application
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|