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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to