java - How is the resource clean up being done in the following Apache HttpClient usage with PoolingHttpClientConnectionManager? -


the code being referred under this question on codereview forum.

when httpclientpool.getclient().execute(request), r) in query method, have used client send httprequest.. don't need release / clean resources ?

does monitor thread's

while ((stoprequest = stopsignal.poll(5, timeunit.seconds)) == null) {       // close expired connections       cm.closeexpiredconnections();       // optionally, close connections have been idle long.       cm.closeidleconnections(60, timeunit.seconds);       // @ pool stats.       log.trace("stats: {}", cm.gettotalstats());     } 

suffice release connection used client obtained pool.

a few questions :

  • does mean let connection expire or go idle them reclaimed pool ?
  • what difference between expiry , going idle ?
  • how physical connections, connection objects, connectionmanager objects, httpclient objects' life cycles maintained , relation between them ?

sorry amateur questions. new httpclient.

the primary cleanup happens in readresponse method content.close(); , response.close();.

the core of mechanism is:

    // start conversation.     closeablehttpresponse response = httpclientpool.getclient().execute(request); 

getclient() pulls closeablehttpclient client pool. singleton thread-safe client not need tidied up, manages multiple uses internally.

execute executes request , returns closeablehttpresponse parsing , processing. cleaned calling close on in readresponse. note closed in finally clause ensure not leak.

    // roll out results     httpentity entity = response.getentity();     if (entity != null) {       inputstream content = entity.getcontent(); 

within readresponse new inputstream created gather content of response - cleaned through closure in finally clause.

the idle thread intended hanging connections left unexpected events, not primary cleanup mechanism.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -