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