且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HttpClient 4.0.1 - 如何释放连接?

更新时间:2023-02-17 15:44:15

要回答我自己的问题:要释放连接(以及与请求关联的任何其他资源),您必须关闭 HttpEntity 返回的 InputStream:

To answer my own question: to release the connection (and any other resources associated with the request) you must close the InputStream returned by the HttpEntity:

InputStream is = entity.getContent();

.... process the input stream ....

is.close();       // releases all resources

来自 文档