From 7f77cfada076b96b7c91f00360f36cf5f8c76a1f Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Mon, 25 Jun 2012 20:33:21 -0400 Subject: [PATCH] Add support for zero queue size in the search thread pool --- .../java/org/elasticsearch/threadpool/ThreadPool.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/threadpool/ThreadPool.java b/src/main/java/org/elasticsearch/threadpool/ThreadPool.java index a79d3fe92fb..3b40b180689 100644 --- a/src/main/java/org/elasticsearch/threadpool/ThreadPool.java +++ b/src/main/java/org/elasticsearch/threadpool/ThreadPool.java @@ -241,9 +241,17 @@ public class ThreadPool extends AbstractComponent { throw new ElasticSearchIllegalArgumentException("reject_policy [" + rejectSetting + "] not valid for [" + name + "] thread pool"); } logger.debug("creating thread_pool [{}], type [{}], size [{}], queue_size [{}], reject_policy [{}]", name, type, size, capacity, rejectSetting); + BlockingQueue workQueue; + if (capacity == null) { + workQueue = new LinkedTransferQueue(); + } else if ((int) capacity.singles() > 0) { + workQueue = new ArrayBlockingQueue((int) capacity.singles()); + } else { + workQueue = new SynchronousQueue(); + } Executor executor = new EsThreadPoolExecutor(size, size, 0L, TimeUnit.MILLISECONDS, - capacity == null ? new LinkedTransferQueue() : new ArrayBlockingQueue((int) capacity.singles()), + workQueue, threadFactory, rejectedExecutionHandler); return new ExecutorHolder(executor, new Info(name, type, size, size, null, capacity)); } else if ("scaling".equals(type)) {