HttpClient_error_Too many open files_如何正确关闭连接和流
HttpClient_error_Too many open files_如何正确关闭连接和流
?
Error:
java.io.FileNotFoundException: /usr/local/app/xxx.jpg (Too many open files)
?
症状分析:
经过检查,读写文件的流都已经正确关闭了,还是报告打开文件数过多
应该就是httpClient的问题了
?
解决:
官方文档HttpClient的API中:
// When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown();
?
另外,如果多个线程使用一个httpClient,注意releaseConnection
public?void?releaseConnection()A convenience method to simplify migration from HttpClient 3.1 API. This method is equivalent to?
reset()
.?
public?void?reset()Resets internal state of the request making it reusable.?参考:?HttpClient容易忽视的细节——连接关闭?http://www.iteye.com/topic/234759http://www.2cto.com/kf/201109/103561.html?===+===