THRIFT-3202: Allow HSHAServer to configure min and max worker threads separately.
Client: java
Patch: Pankaj Kumar
Allow HSHAServer to configure min and max worker thread separately
diff --git a/lib/java/src/org/apache/thrift/server/THsHaServer.java b/lib/java/src/org/apache/thrift/server/THsHaServer.java
index 3541154..2ef4b83 100644
--- a/lib/java/src/org/apache/thrift/server/THsHaServer.java
+++ b/lib/java/src/org/apache/thrift/server/THsHaServer.java
@@ -35,7 +35,8 @@
public class THsHaServer extends TNonblockingServer {
public static class Args extends AbstractNonblockingServerArgs<Args> {
- private int workerThreads = 5;
+ public int minWorkerThreads = 5;
+ public int maxWorkerThreads = Integer.MAX_VALUE;
private int stopTimeoutVal = 60;
private TimeUnit stopTimeoutUnit = TimeUnit.SECONDS;
private ExecutorService executorService = null;
@@ -44,13 +45,22 @@
super(transport);
}
- public Args workerThreads(int i) {
- workerThreads = i;
+ public Args minWorkerThreads(int n) {
+ minWorkerThreads = n;
return this;
}
- public int getWorkerThreads() {
- return workerThreads;
+ public Args maxWorkerThreads(int n) {
+ maxWorkerThreads = n;
+ return this;
+ }
+
+ public int getMinWorkerThreads() {
+ return minWorkerThreads;
+ }
+
+ public int getMaxWorkerThreads() {
+ return maxWorkerThreads;
}
public int getStopTimeoutVal() {
@@ -111,13 +121,14 @@
* Helper to create an invoker pool
*/
protected static ExecutorService createInvokerPool(Args options) {
- int workerThreads = options.workerThreads;
+ int minWorkerThreads = options.minWorkerThreads;
+ int maxWorkerThreads = options.maxWorkerThreads;
int stopTimeoutVal = options.stopTimeoutVal;
TimeUnit stopTimeoutUnit = options.stopTimeoutUnit;
LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
- ExecutorService invoker = new ThreadPoolExecutor(workerThreads,
- workerThreads, stopTimeoutVal, stopTimeoutUnit, queue);
+ ExecutorService invoker = new ThreadPoolExecutor(minWorkerThreads,
+ maxWorkerThreads, stopTimeoutVal, stopTimeoutUnit, queue);
return invoker;
}