parent
dad4e84d35
commit
ffe21175ca
|
@ -20,11 +20,9 @@ import javax.validation.Validation;
|
|||
|
||||
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.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
|
||||
|
||||
|
@ -37,21 +35,11 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage
|
|||
* @since 1.3.0
|
||||
*/
|
||||
@Order(LoggingApplicationListener.DEFAULT_ORDER + 1)
|
||||
public class BackgroundPreinitializer implements ApplicationListener<ApplicationEvent> {
|
||||
|
||||
private volatile Thread initializationThread;
|
||||
public class BackgroundPreinitializer
|
||||
implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
if (event instanceof ApplicationStartedEvent) {
|
||||
performInitialization();
|
||||
}
|
||||
else if (event instanceof ContextRefreshedEvent) {
|
||||
awaitInitialization();
|
||||
}
|
||||
}
|
||||
|
||||
private void performInitialization() {
|
||||
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
|
||||
try {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
|
||||
|
@ -73,7 +61,6 @@ public class BackgroundPreinitializer implements ApplicationListener<Application
|
|||
|
||||
}, "background-preinit");
|
||||
thread.start();
|
||||
this.initializationThread = thread;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// 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.
|
||||
*/
|
||||
|
@ -132,4 +104,5 @@ public class BackgroundPreinitializer implements ApplicationListener<Application
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@
|
|||
<liquibase.version>3.4.2</liquibase.version>
|
||||
<log4j.version>1.2.17</log4j.version>
|
||||
<log4j2.version>2.4.1</log4j2.version>
|
||||
<logback.version>1.1.6</logback.version>
|
||||
<logback.version>1.1.7</logback.version>
|
||||
<mariadb.version>1.2.3</mariadb.version>
|
||||
<mockito.version>1.10.19</mockito.version>
|
||||
<mongodb.version>2.13.3</mongodb.version>
|
||||
|
|
Loading…
Reference in New Issue