hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Question on HTTPClient-675
Date Mon, 15 Jun 2009 21:07:13 GMT
Ortwin Gl├╝ck wrote:
> David,
> 
>> We are still using HttpClient 3.0.1
> 
> Consider upgrading.
> 
>> I saw there is a bug HTTPClient-675 that was fixed by Roland Weber in
>> version 3.1.  It talks about thread-starving in the
>> MultiThreadedHttpConnectionManager and made me wonder if we were seeing
>> something similar occurring.  
> 
> As you are not using the MTCM, that issue does not affect you.
> 
>> I emailed Roland
> 
> Generally you do not email indidivual developers. They might not even bother
> responding.
> 
>>         HttpClient client = new HttpClient();
>>         PostMethod post = new PostMethod(inUrl);
>>         post.setRequestEntity(new StringRequestEntity(inPayload, null,
>> null));
>>         int statusCode = client.executeMethod(post);
>>         log.debug(new StringBuilder("inUrl=").append(inUrl).append(",
>> inPayload=")
>>                     .append(inPayload).append(", statusCode=")
>>                     .append(statusCode).toString());
>>         String payload = readPayload(post);
>>         return payload;
>>
>> The readPayload method just uses post.getResponseBodyAsStream and a
>> BufferedReader to read the response.
>> The BufferedReader is then closed in a finally block.
> 
> This code does not call post.releaseConnection() at all! It will leak
> connections. It could be that you are running out of file descriptors. The call
> should be put into a finally block. See the example code on the website.
> 

David,

Another big issue is that a new instance of HttpClient is created for 
each new request. This is enormously wasteful, as every time there 
likely to be an open connection going out of scope, which needs to be 
GC-ed in order to free up system resources.

You should re-use HttpClient instance for multiple request and shut down 
its connection manager when it is no longer used.

Besides, upgrading to Httpclient 4.0 may be a big jump, but there is no 
excuse for not upgrading to HttpClient 3.1

Oleg


>> Sincerely,
>> David Hamilton
> 
> Hope that helps,
> 
> Ortwin
> 
> 


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


Mime
View raw message