blob: 1ec5455dacded024e8db73cc97aebd2420cd4ed0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.handler;
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.protect.ProcessTerminator;
import com.yahoo.jdisc.Metric;
import java.util.concurrent.Executor;
/**
* A configurable thread pool provider. This provides the worker threads used for normal request processing.
* Request an Executor injected in your component constructor if you want to use it.
*
* @author Steinar Knutsen
* @author baldersheim
* @author bratseth
*/
public class ThreadPoolProvider extends AbstractComponent implements Provider<Executor> {
private final ContainerThreadPool threadpool;
@Inject
public ThreadPoolProvider(ThreadpoolConfig threadpoolConfig, Metric metric) {
this.threadpool = new ContainerThreadPool(threadpoolConfig, metric);
}
public ThreadPoolProvider(ThreadpoolConfig threadpoolConfig, Metric metric, ProcessTerminator processTerminator) {
this.threadpool = new ContainerThreadPool(threadpoolConfig, metric, processTerminator);
}
/**
* Get the Executor provided by this class. This Executor will by default
* also be used for search queries and processing requests.
*
* @return a possibly shared executor
*/
@Override
public Executor get() { return threadpool.executor(); }
/**
* Shutdown the thread pool, give a grace period of 1 second before forcibly
* shutting down all worker threads.
*/
@Override
public void deconstruct() {
threadpool.deconstruct();
}
}
|