问题描述
我正在使用spring rest模板与apache http client 4.2.1集成在一起发送REST请求.
I am using spring rest template to send REST request with apache http client 4.2.1 intergrated.
由于我们需要向多个服务器发送请求,因此添加了PoolingClientConnectionManager来管理连接.
As we need send request to multiple server, added PoolingClientConnectionManager to manager the connections.
将每条路线的最大值设置为5connectionManager.setDefaultMaxPerRoute(5)
Set the max per route to 5connectionManager.setDefaultMaxPerRoute(5)
系统运行几天后,我们发现每个路由设置的连接数已达到最大值.
While after the system running for few days, we found that the connection reached the maxmium per route settings.
打印的日志如下总计存活:0;分配的路线:5之5;已分配的总数:100个中的5个
Printed log as belowtotal kept alive: 0; route allocated: 5 of 5; total allocated: 5 of 100
似乎由于某种原因未释放连接.但是,当我调试时,每次请求完成后我都会发现,即使发生异常,连接也会被释放.
Seems the connection is not released by some reason. But when i debug, i found every time after request is finished, the connection will be released even there's exception happens.
此连接是否还有其他潜在的根本原因无法解决?
Is there any other potential root cause of this connection cannot be released?
推荐答案
这是因为在某些情况下,服务器保留了请求,因此我们需要为http客户端添加超时
It's because in some case, the server hold the request, we need add timeout for http client
这篇关于Apache Httpclient连接未释放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!