当我使用没有拦截器的连接时,一切正常:
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(socketTimeout)
.setConnectTimeout(connectTimeout)
.setConnectionRequestTimeout(connectionRequestTimeout)
.build();
return HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.addInterceptorFirst(new RemoveSoapHeadersInterceptor())
.setSSLSocketFactory(sslConnectionSocketFactory())
.setMaxConnPerRoute(maxConnPerRoute)
.disableCookieManagement()
.setMaxConnTotal(maxHTTPConnectionsTotal)
.setDefaultHeaders(headers).build();
}
但当我添加拦截器时,一段时间后我收到“timeout waiting for connection from pool;嵌套异常是org.apache.http.conn.connectionpooltimeoutexception“我应该使用任何手动关闭连接吗,或者异常的原因是什么?
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(socketTimeout)
.setConnectTimeout(connectTimeout)
.setConnectionRequestTimeout(connectionRequestTimeout)
.build();
return HttpClientBuilder.create()
.addInterceptorLast(httpRequestInterceptor)
.addInterceptorLast(httpResponseInterceptor)
.setRetryHandler(httpExceptionHandler)
.setDefaultRequestConfig(requestConfig)
.addInterceptorFirst(new RemoveSoapHeadersInterceptor())
.setSSLSocketFactory(sslConnectionSocketFactory())
.setMaxConnPerRoute(maxConnPerRoute)
.disableCookieManagement()
.setMaxConnTotal(maxHTTPConnectionsTotal)
.setDefaultHeaders(headers).build();
}
暂无答案!
目前还没有任何答案,快来回答吧!