You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Ortwin Glück <od...@odi.ch> on 2007/07/01 12:32:07 UTC
Re: [HttpClient] Connection release in HttpClient 4.0 (Look ma, no
more try - finally - releaseConnection!)
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
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; }
}
Odi
---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org
Re: [HttpClient] Connection release in HttpClient 4.0 (Look ma, no
more try - finally - releaseConnection!)
Posted by Ortwin Glück <od...@odi.ch>.
Oleg Kalnichevski wrote:
> You are absolutely right. We ought not encourage sloppy programming
> practices.
>
> Made some tweaks to the sample. Please review.
>
> Oleg
Cool, now it looks like most developers would probably expect it.
Cheers
Odi
---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org
Re: [HttpClient] Connection release in HttpClient 4.0 (Look ma, no
more try - finally - releaseConnection!)
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sun, 2007-07-01 at 12:32 +0200, Ortwin Glück wrote:
> 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
>
> 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).
>
You are absolutely right. We ought not encourage sloppy programming
practices.
Made some tweaks to the sample. Please review.
Oleg
> BufferedReader r = null;
> try {
> r = ...
> ...
> } finally {
> if (r != null) { r.close(); r = null; }
> }
>
> Odi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org