hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ortwin Gl├╝ck <...@odi.ch>
Subject Re: [HttpClient] Connection release in HttpClient 4.0 (Look ma, no more try - finally - releaseConnection!)
Date Sun, 01 Jul 2007 10:32:07 GMT
Oleg Kalnichevski wrote:
> Folks
> I put together a sample demonstrating the recommended way of making sure
> connection gets released back to the connection manager.
> Please review
> http://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientConnectionRelease.java
> Oleg


Nice one. I would still put the reader.close() into a finally clause, though.
That's the recommended pattern to deal with streams anyway. Failure to close a
stream that you have opened generally screams of a leak somewhere. Maybe our API
may not require it, but that is an implementation detail, which is not obvious.
I can find nothing "ugly" about a finally clause. It is THE construct for proper
resource management in Java (until we get closures in 1.7, that is).

BufferedReader r = null;
try {
  r = ...
} finally {
  if (r != null) { r.close(); r = null; }


To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org

View raw message