2015/04/07

htmlClient EntityUtils.consume?? why

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();
}
 
 What EntityUtils.consume will do is release all resources held by the httpEntity,
 which essentially implies releasing any underlying Stream and giving 
the Connection object back to its pool (in the case your connection 
manager is a multithreaded one) or freeing the connection manager so 
that it can process the next request.


何かメモリを開放するみたいね