Skip to content

Commit 7dd6507

Browse files
committed
Only perform background pre-init with multiple processors
Closes gh-15722
1 parent 32b14f3 commit 7dd6507

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,7 +70,7 @@ public class BackgroundPreinitializer
7070
@Override
7171
public void onApplicationEvent(SpringApplicationEvent event) {
7272
if (!Boolean.getBoolean(IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME)
73-
&& event instanceof ApplicationStartingEvent
73+
&& event instanceof ApplicationStartingEvent && multipleProcessors()
7474
&& preinitializationStarted.compareAndSet(false, true)) {
7575
performPreinitialization();
7676
}
@@ -86,6 +86,10 @@ public void onApplicationEvent(SpringApplicationEvent event) {
8686
}
8787
}
8888

89+
private boolean multipleProcessors() {
90+
return Runtime.getRuntime().availableProcessors() > 1;
91+
}
92+
8993
private void performPreinitialization() {
9094
try {
9195
Thread thread = new Thread(new Runnable() {

0 commit comments

Comments
 (0)