Commit 6f8d4c77 authored by Andy Wilkinson's avatar Andy Wilkinson

Handle multiple ContextRefreshedEvents in BackgroundPreinitializer

The same initializer will receive multiple ContextRefreshedEvents
when their is an application context hierarchy. This commit updates
the initializer to correctly handle multiple ContextRefreshedEvents
and only act upon the first that it receives.

See gh-4871
parent 992e90f4
......@@ -53,7 +53,7 @@ public class BackgroundPreinitializer implements ApplicationListener<Application
private void performInitialization() {
try {
this.initializationThread = new Thread(new Runnable() {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
......@@ -72,7 +72,8 @@ public class BackgroundPreinitializer implements ApplicationListener<Application
}
}, "background-preinit");
this.initializationThread.start();
thread.start();
this.initializationThread = thread;
}
catch (Exception ex) {
// This will fail on GAE where creating threads is prohibited. We can safely
......@@ -82,14 +83,17 @@ public class BackgroundPreinitializer implements ApplicationListener<Application
}
private void awaitInitialization() {
try {
this.initializationThread.join();
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
finally {
this.initializationThread = null;
Thread thread = this.initializationThread;
if (thread != null) {
try {
thread.join();
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
finally {
this.initializationThread = null;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment