从ExecutorService发出HTTP请求时的ConnectionPoolTimeoutException

时间:2018-01-18 06:41:14

标签: java executorservice

我有一个方法进行HTTP调用 - putObject(Object obj);

我正在执行它:

private static final int THREAD_COUNT = 64;

ExecutorService threadPool = Executors.newFixedThreadPool(THREAD_COUNT);
for (Object obj : listOfObj) {
    threadPool.submit(() -> putObject(obj));
}
threadPool.shutdown();
threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);

在进行~300次调用之后,很少有人调用putObject()抛出ConnectionPoolTimeoutException。

如果我将方法的调用从ExecutorService更改为其他东西(如CompletableFuture),我不会遇到这个问题。

完整的异常堆栈:

[junit] org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
[junit]     at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:286)
[junit]     at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$1.get(PoolingHttpClientConnectionManager.java:263)
[junit]     at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:190)
[junit]     at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
[junit]     at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
[junit]     at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
[junit]     at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
[junit]     at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
[junit]     at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)

任何人都可以对此有任何想法吗?我无法弄明白。欣赏它。

0 个答案:

没有答案