Skip to content

Commit 210c51e

Browse files
committed
Merge pull request #16115 from JWThewes
* pr/16115: Polish "Check for multiple processors in OnClassCondition" Check for multiple processors in OnClassCondition
2 parents 9da20b7 + 4d73211 commit 210c51e

File tree

1 file changed

+17
-3
lines changed
  • spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition

1 file changed

+17
-3
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,23 @@ class OnClassCondition extends FilteringSpringBootCondition {
4646
@Override
4747
protected final ConditionOutcome[] getOutcomes(String[] autoConfigurationClasses,
4848
AutoConfigurationMetadata autoConfigurationMetadata) {
49-
// Split the work and perform half in a background thread. Using a single
50-
// additional thread seems to offer the best performance. More threads make
51-
// things worse
49+
// Split the work and perform half in a background thread if more than one
50+
// processor is available. Using a single additional thread seems to offer the
51+
// best performance. More threads make things worse.
52+
if (Runtime.getRuntime().availableProcessors() > 1) {
53+
return resolveOutcomesThreaded(autoConfigurationClasses,
54+
autoConfigurationMetadata);
55+
}
56+
else {
57+
OutcomesResolver outcomesResolver = new StandardOutcomesResolver(
58+
autoConfigurationClasses, 0, autoConfigurationClasses.length,
59+
autoConfigurationMetadata, getBeanClassLoader());
60+
return outcomesResolver.resolveOutcomes();
61+
}
62+
}
63+
64+
private ConditionOutcome[] resolveOutcomesThreaded(String[] autoConfigurationClasses,
65+
AutoConfigurationMetadata autoConfigurationMetadata) {
5266
int split = autoConfigurationClasses.length / 2;
5367
OutcomesResolver firstHalfResolver = createOutcomesResolver(
5468
autoConfigurationClasses, 0, split, autoConfigurationMetadata);

0 commit comments

Comments
 (0)