mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-27 00:40:51 +01:00
3.x
Committed-by: Eduard Heimbuch<eduard.heimbuch@cloudogu.com> Pushed-by: Rene Pfeuffer<rene.pfeuffer@cloudogu.com> Co-authored-by: René Pfeuffer<rene.pfeuffer@cloudogu.com> Pushed-by: Eduard Heimbuch<eduard.heimbuch@cloudogu.com> Committed-by: René Pfeuffer<rene.pfeuffer@cloudogu.com>
This commit is contained in:
committed by
René Pfeuffer
parent
d760f46d9d
commit
cf4d9cf20f
@@ -38,31 +38,28 @@ public class ThreadCountProvider implements IntSupplier {
|
||||
static final String PROPERTY = "scm.central-work-queue.workers";
|
||||
|
||||
private final IntSupplier cpuCountProvider;
|
||||
private final Integer workers;
|
||||
|
||||
public ThreadCountProvider() {
|
||||
this(() -> Runtime.getRuntime().availableProcessors());
|
||||
public ThreadCountProvider(Integer workers) {
|
||||
this(() -> Runtime.getRuntime().availableProcessors(), workers);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
ThreadCountProvider(IntSupplier cpuCountProvider) {
|
||||
ThreadCountProvider(IntSupplier cpuCountProvider, Integer workers) {
|
||||
this.cpuCountProvider = cpuCountProvider;
|
||||
this.workers = workers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
Integer systemProperty = Integer.getInteger(PROPERTY);
|
||||
if (systemProperty == null) {
|
||||
LOG.debug("derive worker count from cpu count");
|
||||
return deriveFromCPUCount();
|
||||
}
|
||||
if (isInvalid(systemProperty)) {
|
||||
if (isInvalid(workers)) {
|
||||
LOG.warn(
|
||||
"system property {} contains a invalid value {}, fall back and derive worker count from cpu count",
|
||||
PROPERTY, systemProperty
|
||||
"config value {} contains a invalid value {}, fall back and derive worker count from cpu count",
|
||||
"central-work-queue.workers", workers
|
||||
);
|
||||
return deriveFromCPUCount();
|
||||
}
|
||||
return systemProperty;
|
||||
return workers;
|
||||
}
|
||||
|
||||
private boolean isInvalid(int value) {
|
||||
|
||||
Reference in New Issue
Block a user