【发布时间】:2013-04-12 10:31:09
【问题描述】:
我遇到过EntityUtils.consume(httpEntity);,但我不确定它的真正作用。
例如:
try {
//... some code
HttpEntity httpEntity = httpResponse.getEntity();
BufferedReader br = new BufferedReader(new InputStreamReader(http.Entity.getContent()));
String line;
while ((line = br.readLine())!= null) {
System.out.println(line);
}
EntityUtils.consume(httpEntity);
} catch (Exception e) {
//code
} finally {
httpClient.getConnectionManager().shutdown();
}
为什么作者在finally块将关闭连接而垃圾收集器将处理httpEntity时放入EntityUtils.consume(httpEntity);?
【问题讨论】:
标签: java apache-httpclient-4.x