diff --git a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java index 6bfd36af94b4..6d5998633797 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java +++ b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java @@ -60,6 +60,7 @@ import java.util.concurrent.CompletionService; import java.util.concurrent.ExecutorCompletionService; import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.TimeUnit; @@ -191,9 +192,7 @@ public void init(PluginInfo info) { r.setSeed(Long.parseLong(v)); } - BlockingQueue blockingQueue = (this.queueSize == -1) ? - new SynchronousQueue(this.accessPolicy) : - new ArrayBlockingQueue(this.queueSize, this.accessPolicy); + BlockingQueue blockingQueue = getBlockingQueue(); this.commExecutor = new ExecutorUtil.MDCAwareThreadPoolExecutor( this.corePoolSize, @@ -210,6 +209,21 @@ public void init(PluginInfo info) { this.loadbalancer = createLoadbalancer(defaultClient); } + private BlockingQueue getBlockingQueue() { + if (this.queueSize == -1) { + if (this.maximumPoolSize == Integer.MAX_VALUE) { + return new SynchronousQueue(this.accessPolicy); + } else { + // A limited maximumPoolSize would result in new tasks being rejected + // once the pool is full, with SynchronousQueue, so it's better to accept + // as many as we're offered and let the pool work through them + return new LinkedBlockingQueue<>(); + } + } else { + return new ArrayBlockingQueue(this.queueSize, this.accessPolicy); + } + } + protected ModifiableSolrParams getClientParams() { ModifiableSolrParams clientParams = new ModifiableSolrParams(); clientParams.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost);