From a96a79ea45b00be34e84b34af96b4bc45f50bcee Mon Sep 17 00:00:00 2001 From: Jan Thewes Date: Wed, 6 Mar 2019 13:57:04 +0100 Subject: [PATCH 1/2] Check for multiple processors in OnClassCondition See gh-16115 --- .../condition/OnClassCondition.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java index 80239abf2c..b23b1a8a56 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java @@ -49,6 +49,25 @@ class OnClassCondition extends FilteringSpringBootCondition { // Split the work and perform half in a background thread. Using a single // additional thread seems to offer the best performance. More threads make // things worse + if (Runtime.getRuntime().availableProcessors() > 1) { + return resolveOutcomesThreaded(autoConfigurationClasses, + autoConfigurationMetadata); + } + else { + return resolveOutcomes(autoConfigurationClasses, autoConfigurationMetadata); + } + } + + private ConditionOutcome[] resolveOutcomes(String[] autoConfigurationClasses, + AutoConfigurationMetadata autoConfigurationMetadata) { + OutcomesResolver outcomesResolver = createOutcomesResolver( + autoConfigurationClasses, 0, autoConfigurationClasses.length, + autoConfigurationMetadata); + return outcomesResolver.resolveOutcomes(); + } + + private ConditionOutcome[] resolveOutcomesThreaded(String[] autoConfigurationClasses, + AutoConfigurationMetadata autoConfigurationMetadata) { int split = autoConfigurationClasses.length / 2; OutcomesResolver firstHalfResolver = createOutcomesResolver( autoConfigurationClasses, 0, split, autoConfigurationMetadata); From 4d73211c3a65d298580b6379a3ea13a3792ed494 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 13 Mar 2019 18:13:33 +0100 Subject: [PATCH 2/2] Polish "Check for multiple processors in OnClassCondition" Closes gh-16115 --- .../condition/OnClassCondition.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java index b23b1a8a56..355cff9df3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java @@ -46,26 +46,21 @@ class OnClassCondition extends FilteringSpringBootCondition { @Override protected final ConditionOutcome[] getOutcomes(String[] autoConfigurationClasses, AutoConfigurationMetadata autoConfigurationMetadata) { - // Split the work and perform half in a background thread. Using a single - // additional thread seems to offer the best performance. More threads make - // things worse + // Split the work and perform half in a background thread if more than one + // processor is available. Using a single additional thread seems to offer the + // best performance. More threads make things worse. if (Runtime.getRuntime().availableProcessors() > 1) { return resolveOutcomesThreaded(autoConfigurationClasses, autoConfigurationMetadata); } else { - return resolveOutcomes(autoConfigurationClasses, autoConfigurationMetadata); + OutcomesResolver outcomesResolver = new StandardOutcomesResolver( + autoConfigurationClasses, 0, autoConfigurationClasses.length, + autoConfigurationMetadata, getBeanClassLoader()); + return outcomesResolver.resolveOutcomes(); } } - private ConditionOutcome[] resolveOutcomes(String[] autoConfigurationClasses, - AutoConfigurationMetadata autoConfigurationMetadata) { - OutcomesResolver outcomesResolver = createOutcomesResolver( - autoConfigurationClasses, 0, autoConfigurationClasses.length, - autoConfigurationMetadata); - return outcomesResolver.resolveOutcomes(); - } - private ConditionOutcome[] resolveOutcomesThreaded(String[] autoConfigurationClasses, AutoConfigurationMetadata autoConfigurationMetadata) { int split = autoConfigurationClasses.length / 2;