From 2238adabbc5317ab59ee1b13d4df4e1d4d889c73 Mon Sep 17 00:00:00 2001 From: jfarrell Date: Fri, 26 Jun 2015 08:58:32 -0400 Subject: 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 --- .../src/org/apache/thrift/server/THsHaServer.java | 27 +++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'lib/java') diff --git a/lib/java/src/org/apache/thrift/server/THsHaServer.java b/lib/java/src/org/apache/thrift/server/THsHaServer.java index 354115403..2ef4b8358 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 @@ import org.apache.thrift.transport.TNonblockingServerTransport; public class THsHaServer extends TNonblockingServer { public static class Args extends AbstractNonblockingServerArgs { - 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 @@ public class THsHaServer extends TNonblockingServer { 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 @@ public class THsHaServer extends TNonblockingServer { * 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 queue = new LinkedBlockingQueue(); - ExecutorService invoker = new ThreadPoolExecutor(workerThreads, - workerThreads, stopTimeoutVal, stopTimeoutUnit, queue); + ExecutorService invoker = new ThreadPoolExecutor(minWorkerThreads, + maxWorkerThreads, stopTimeoutVal, stopTimeoutUnit, queue); return invoker; } -- cgit v1.2.1