Commit 42eec50e authored by Andy Wilkinson's avatar Andy Wilkinson

Perform background preinitialization once per class loader

Background preinitialization triggers static initialization of a
number of components that are slow to initialize. As the
initialization is static, it's only necessary once per class loader.

Previously, a new background preinitialization thread would be
created and started for each ApplicationEnvironmentPreparedEvent.
This commit updates the preinitializer to only create and start the
thread if preinitialization has not already been started for the
current class loader.

Closes gh-9869
parent 6f864c62
......@@ -16,6 +16,8 @@
package org.springframework.boot.autoconfigure;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.validation.Validation;
import org.apache.catalina.mbeans.MBeanFactory;
......@@ -40,8 +42,16 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage
public class BackgroundPreinitializer
implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
private static final AtomicBoolean preinitalizationStarted = new AtomicBoolean(false);
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
if (preinitalizationStarted.compareAndSet(false, true)) {
performPreinitialization();
}
}
private void performPreinitialization() {
try {
Thread thread = new Thread(new Runnable() {
......
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