我遇到过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();
}
为什么作者在EntityUtils.consume(httpEntity);
blockfinally
会关闭连接和garbage collector会处理的时候放入httpEntity
?