`
fantaxy025025
  • 浏览: 1251922 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类

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/234759
http://www.2cto.com/kf/201109/103561.html
 
=
=
=
+
=
=
=
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics