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)) {