ableHttpAsyncClient的TimeoutExcep

ableHttpAsyncClient的TimeoutExcep

本文介绍了CloseableHttpAsyncClient的TimeoutException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 CloseableHttpAsyncClient 连接消耗api。我使用45的连接池和5分钟的超时时间对api进行了调用。但是,我收到以下错误:

i am trying to connect consume api using CloseableHttpAsyncClient. I making call to the api with connection pool of 45 and timeout of 5 minutes. However, i get the following error:

java.util.concurrent.TimeoutException: null
    at org.apache.http.nio.pool.AbstractNIOConnPool.processPendingRequest(AbstractNIOConnPool.java:364)
    at org.apache.http.nio.pool.AbstractNIOConnPool.processNextPendingRequest(AbstractNIOConnPool.java:344)
    at org.apache.http.nio.pool.AbstractNIOConnPool.release(AbstractNIOConnPool.java:318)
    at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.releaseConnection(PoolingNHttpClientConnectionManager.java:303)
    at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.releaseConnection(AbstractClientExchangeHandler.java:239)
    at org.apache.http.impl.nio.client.MainClientExec.responseCompleted(MainClientExec.java:387)
    at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseCompleted(DefaultClientExchangeHandlerImpl.java:168)
    at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:436)
    at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:326)
    at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:265)
    at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
    at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
    at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114)
    at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
    at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
    at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
    at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
    at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
    at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588)
    at java.lang.Thread.run(Thread.java:745)

然后将连接池大小减小到10,则抛出错误的次数减少了。

Then on reducing the connection pool size to 10, the number of times error is thrown is down.

我正在使用 CloseableHttpAsyncClient ,请不要关闭它以加快通话速度。

i am using singleton instance of CloseableHttpAsyncClient, and do not close it for faster call.

这就是我所说的:

httpclient.execute(post, new FutureCallback<HttpResponse>(....));

我认为,这不是从api方面考虑的。
是否知道发生此异常以及它与连接池之间是否有任何连接?

i think, it is NOT from the api side.any idea which this exception occurs and does it has any connection from connection pool?

推荐答案

通过查看源代码代码,当您将connectionRequestTimeout设置为与连接管理器(例如PoolingNHttpClientConnectionManager)中的默认值(-1)不同的值时,就会发生这种情况。如果池非常繁忙并且超时不足,它将引发此异常。

By looking at the source code, this happens when you set connectionRequestTimeout to a value different than the default (-1) in the connection manager (e.g. PoolingNHttpClientConnectionManager). If the pool is very busy and timeout is not enough, it will throw this exception.

要解决此问题,请增加连接管理器池的connectionRequestTimeout或将其设置为-1(无限期等待)。

To solve it, either increase the connectionRequestTimeout of the connection manager pool or set it to -1 (for indefinite wait).

这篇关于CloseableHttpAsyncClient的TimeoutException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 01:16