Merge pull request #16115 from JWThewes

* pr/16115:
  Polish "Check for multiple processors in OnClassCondition"
  Check for multiple processors in OnClassCondition
pull/16225/head
Stephane Nicoll 6 years ago
commit 210c51e31c

@ -46,9 +46,23 @@ class OnClassCondition extends FilteringSpringBootCondition {
@Override @Override
protected final ConditionOutcome[] getOutcomes(String[] autoConfigurationClasses, protected final ConditionOutcome[] getOutcomes(String[] autoConfigurationClasses,
AutoConfigurationMetadata autoConfigurationMetadata) { AutoConfigurationMetadata autoConfigurationMetadata) {
// Split the work and perform half in a background thread. Using a single // Split the work and perform half in a background thread if more than one
// additional thread seems to offer the best performance. More threads make // processor is available. Using a single additional thread seems to offer the
// things worse // best performance. More threads make things worse.
if (Runtime.getRuntime().availableProcessors() > 1) {
return resolveOutcomesThreaded(autoConfigurationClasses,
autoConfigurationMetadata);
}
else {
OutcomesResolver outcomesResolver = new StandardOutcomesResolver(
autoConfigurationClasses, 0, autoConfigurationClasses.length,
autoConfigurationMetadata, getBeanClassLoader());
return outcomesResolver.resolveOutcomes();
}
}
private ConditionOutcome[] resolveOutcomesThreaded(String[] autoConfigurationClasses,
AutoConfigurationMetadata autoConfigurationMetadata) {
int split = autoConfigurationClasses.length / 2; int split = autoConfigurationClasses.length / 2;
OutcomesResolver firstHalfResolver = createOutcomesResolver( OutcomesResolver firstHalfResolver = createOutcomesResolver(
autoConfigurationClasses, 0, split, autoConfigurationMetadata); autoConfigurationClasses, 0, split, autoConfigurationMetadata);

Loading…
Cancel
Save