aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo/container/handler
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2020-09-07 15:06:24 +0200
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2020-09-07 17:53:16 +0200
commitab8b4e97ccea563b3e481e59a689f1f9d5b2386f (patch)
tree47e878e46c90b08b7073ed6b888dfbcd9e5b2bcf /container-core/src/main/java/com/yahoo/container/handler
parent4c5492d00a012b833fe24decb72c5c54f690fd79 (diff)
Use separate non-public config definition for ContainerThreadPool
Diffstat (limited to 'container-core/src/main/java/com/yahoo/container/handler')
-rw-r--r--container-core/src/main/java/com/yahoo/container/handler/ThreadPoolProvider.java24
-rw-r--r--container-core/src/main/java/com/yahoo/container/handler/threadpool/ContainerThreadPool.java19
2 files changed, 29 insertions, 14 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/handler/ThreadPoolProvider.java b/container-core/src/main/java/com/yahoo/container/handler/ThreadPoolProvider.java
index 425387039ff..dc594903f21 100644
--- a/container-core/src/main/java/com/yahoo/container/handler/ThreadPoolProvider.java
+++ b/container-core/src/main/java/com/yahoo/container/handler/ThreadPoolProvider.java
@@ -5,6 +5,7 @@ import com.google.inject.Inject;
import com.yahoo.component.AbstractComponent;
import com.yahoo.container.di.componentgraph.Provider;
import com.yahoo.container.handler.threadpool.ContainerThreadPool;
+import com.yahoo.container.handler.threadpool.ContainerThreadpoolConfig;
import com.yahoo.container.protect.ProcessTerminator;
import com.yahoo.jdisc.Metric;
@@ -23,12 +24,27 @@ public class ThreadPoolProvider extends AbstractComponent implements Provider<Ex
private final ContainerThreadPool threadpool;
@Inject
- public ThreadPoolProvider(ThreadpoolConfig threadpoolConfig, Metric metric) {
- this.threadpool = new ContainerThreadPool(threadpoolConfig, metric);
+ public ThreadPoolProvider(ThreadpoolConfig config, Metric metric) {
+ this.threadpool = new ContainerThreadPool(translateConfig(config), metric);
}
- public ThreadPoolProvider(ThreadpoolConfig threadpoolConfig, Metric metric, ProcessTerminator processTerminator) {
- this.threadpool = new ContainerThreadPool(threadpoolConfig, metric, processTerminator);
+ public ThreadPoolProvider(ThreadpoolConfig config, Metric metric, ProcessTerminator processTerminator) {
+ this.threadpool = new ContainerThreadPool(translateConfig(config), metric, processTerminator);
+ }
+
+ /**
+ * The underlying {@link ContainerThreadPool} uses a different config definition ({@link ContainerThreadpoolConfig})
+ * as {@link ThreadpoolConfig} is currently public api.
+ */
+ private static ContainerThreadpoolConfig translateConfig(ThreadpoolConfig config) {
+ return new ContainerThreadpoolConfig(
+ new ContainerThreadpoolConfig.Builder()
+ .maxThreads(config.maxthreads())
+ .minThreads(config.corePoolSize())
+ .name(config.name())
+ .queueSize(config.queueSize())
+ .keepAliveTime(config.keepAliveTime())
+ .maxThreadExecutionTimeSeconds(config.maxThreadExecutionTimeSeconds()));
}
/**
diff --git a/container-core/src/main/java/com/yahoo/container/handler/threadpool/ContainerThreadPool.java b/container-core/src/main/java/com/yahoo/container/handler/threadpool/ContainerThreadPool.java
index 74bcb3a2e04..e2d38427de1 100644
--- a/container-core/src/main/java/com/yahoo/container/handler/threadpool/ContainerThreadPool.java
+++ b/container-core/src/main/java/com/yahoo/container/handler/threadpool/ContainerThreadPool.java
@@ -4,7 +4,6 @@ package com.yahoo.container.handler.threadpool;
import com.google.inject.Inject;
import com.yahoo.component.AbstractComponent;
import com.yahoo.concurrent.ThreadFactoryFactory;
-import com.yahoo.container.handler.ThreadpoolConfig;
import com.yahoo.container.protect.ProcessTerminator;
import com.yahoo.jdisc.Metric;
@@ -27,26 +26,26 @@ public class ContainerThreadPool extends AbstractComponent implements AutoClosea
private final ExecutorServiceWrapper threadpool;
@Inject
- public ContainerThreadPool(ThreadpoolConfig config, Metric metric) {
+ public ContainerThreadPool(ContainerThreadpoolConfig config, Metric metric) {
this(config, metric, new ProcessTerminator());
}
- public ContainerThreadPool(ThreadpoolConfig threadpoolConfig, Metric metric, ProcessTerminator processTerminator) {
- ThreadPoolMetric threadPoolMetric = new ThreadPoolMetric(metric, threadpoolConfig.name());
- int maxNumThreads = computeMaximumThreadPoolSize(threadpoolConfig.maxthreads());
- int coreNumThreads = computeCoreThreadPoolSize(threadpoolConfig.corePoolSize(), maxNumThreads);
+ public ContainerThreadPool(ContainerThreadpoolConfig config, Metric metric, ProcessTerminator processTerminator) {
+ ThreadPoolMetric threadPoolMetric = new ThreadPoolMetric(metric, config.name());
+ int maxNumThreads = computeMaximumThreadPoolSize(config.maxThreads());
+ int coreNumThreads = computeCoreThreadPoolSize(config.minThreads(), maxNumThreads);
WorkerCompletionTimingThreadPoolExecutor executor =
new WorkerCompletionTimingThreadPoolExecutor(coreNumThreads, maxNumThreads,
- (int)threadpoolConfig.keepAliveTime() * 1000, TimeUnit.MILLISECONDS,
- createQ(threadpoolConfig.queueSize(), maxNumThreads),
- ThreadFactoryFactory.getThreadFactory(threadpoolConfig.name()),
+ (int)config.keepAliveTime() * 1000, TimeUnit.MILLISECONDS,
+ createQ(config.queueSize(), maxNumThreads),
+ ThreadFactoryFactory.getThreadFactory(config.name()),
threadPoolMetric);
// Prestart needed, if not all threads will be created by the fist N tasks and hence they might also
// get the dreaded thread locals initialized even if they will never run.
// That counters what we we want to achieve with the Q that will prefer thread locality.
executor.prestartAllCoreThreads();
threadpool = new ExecutorServiceWrapper(executor, threadPoolMetric, processTerminator,
- threadpoolConfig.maxThreadExecutionTimeSeconds() * 1000L);
+ config.maxThreadExecutionTimeSeconds() * 1000L);
}
public Executor executor() { return threadpool; }