From: Mark Slee Date: Thu, 10 Jan 2008 19:57:47 +0000 (+0000) Subject: Chagnge TThreadPoolServer in Java to use SynchronousQueue by default X-Git-Tag: 0.2.0~1053 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=19c9777583bf4614a237be824bbed80fa6db9213;p=common%2Fthrift.git Chagnge TThreadPoolServer in Java to use SynchronousQueue by default Summary: Read the documentation on ThreadPoolExecutor. It's very confusing. Basically, what we want is a queue that always defers to the threadpool and will always create a new thread to do work. We never want the queue to take priority over the thread pool by default. Reviewed By: dreiss Test Plan: Run a Java Thrift server git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665419 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/java/src/server/TThreadPoolServer.java b/lib/java/src/server/TThreadPoolServer.java index 94eb5a6b..343af6b0 100644 --- a/lib/java/src/server/TThreadPoolServer.java +++ b/lib/java/src/server/TThreadPoolServer.java @@ -18,14 +18,14 @@ import com.facebook.thrift.transport.TTransportException; import com.facebook.thrift.transport.TTransportFactory; import java.util.concurrent.ExecutorService; -import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; /** * Server which uses Java's built in ThreadPool management to spawn off - * a worker pool that + * a worker pool that * * @author Mark Slee */ @@ -50,7 +50,7 @@ public class TThreadPoolServer extends TServer { public TThreadPoolServer(TProcessor processor, TServerTransport serverTransport) { - this(processor, serverTransport, + this(processor, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), new Options()); @@ -58,7 +58,7 @@ public class TThreadPoolServer extends TServer { public TThreadPoolServer(TProcessorFactory processorFactory, TServerTransport serverTransport) { - this(processorFactory, serverTransport, + this(processorFactory, serverTransport, new TTransportFactory(), new TTransportFactory(), new TBinaryProtocol.Factory(), new TBinaryProtocol.Factory(), new Options()); @@ -77,7 +77,7 @@ public class TThreadPoolServer extends TServer { TServerTransport serverTransport, TTransportFactory transportFactory, TProtocolFactory protocolFactory) { - this(processor, serverTransport, + this(processor, serverTransport, transportFactory, transportFactory, protocolFactory, protocolFactory, new Options()); @@ -87,13 +87,13 @@ public class TThreadPoolServer extends TServer { TServerTransport serverTransport, TTransportFactory transportFactory, TProtocolFactory protocolFactory) { - this(processorFactory, serverTransport, + this(processorFactory, serverTransport, transportFactory, transportFactory, protocolFactory, protocolFactory, new Options()); } - + public TThreadPoolServer(TProcessor processor, TServerTransport serverTransport, TTransportFactory inputTransportFactory, @@ -106,7 +106,7 @@ public class TThreadPoolServer extends TServer { inputProtocolFactory, outputProtocolFactory, options); } - + public TThreadPoolServer(TProcessorFactory processorFactory, TServerTransport serverTransport, TTransportFactory inputTransportFactory, @@ -114,14 +114,14 @@ public class TThreadPoolServer extends TServer { TProtocolFactory inputProtocolFactory, TProtocolFactory outputProtocolFactory, Options options) { - super(processorFactory, serverTransport, + super(processorFactory, serverTransport, inputTransportFactory, outputTransportFactory, inputProtocolFactory, outputProtocolFactory); executorService_ = null; - LinkedBlockingQueue executorQueue = - new LinkedBlockingQueue(); + SynchronousQueue executorQueue = + new SynchronousQueue(); executorService_ = new ThreadPoolExecutor(options.minWorkerThreads, options.maxWorkerThreads, @@ -153,7 +153,7 @@ public class TThreadPoolServer extends TServer { ++failureCount; ttx.printStackTrace(); } - } + } } executorService_.shutdown();