我遇到过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();
}
Run Code Online (Sandbox Code Playgroud)
为什么作者在块关闭连接EntityUtils.consume(httpEntity);时放入finally并且垃圾收集器会处理httpEntity?