hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Marc Spaggiari <jean-m...@spaggiari.org>
Subject Re: Right way to timeout
Date Mon, 17 Dec 2012 13:29:30 GMT
Thanks for sharing.

I was doing that the oposite way. I mean, I was starting the request
on a thread, checkinv every 100ms if it was done, and killing it after
a certain period of time. But some time the abort was not working and
it was feeling my memory with pending threads...

If I use such a solution, does it mean that the 2 TimeOut that I'm
already setting are useless? Will the abort close both the TCP and the
HTTP connections?

Thanks,

JM

2012/12/16, Stephen J. Butler <stephen.butler@gmail.com>:
> setConnectionTimeout() only sets a timeout on the initial TCP connection
> request. And setSoTimeout() sets a timeout on the socket operations. But if
> the server is responding to normal TCP packets (whether they have any
> payload or not) then this timeout will never be reached.
>
> If you want to set a timeout on an overall HTTP operation you should setup
> your own thread and call .abort() on the request (this method is
> thread-safe). For example, I use this class and create a new instance of it
> for every request I want to timeout. When I get a response, I interrupt my
> timeout thread.
>
> http://pastebin.com/sRZdZuKx
>
>
> On Sun, Dec 16, 2012 at 7:11 PM, Jean-Marc Spaggiari <
> jean-marc@spaggiari.org> wrote:
>
>> Hi,
>>
>> What's the "right" way to configure the timeout with HttpClient 4.2.1?
>>
>> Here is what I'm doing:
>>
>>                         HttpParams params = client.getParams();
>>                         HttpConnectionParams.setConnectionTimeout(params,
>> 30000);
>>                         HttpConnectionParams.setSoTimeout(params, 30000);
>>                         result.result = client.execute (method);
>>
>> But I don't think it's working. Sometime it's taking way more than 30
>> seconds.
>>
>> How should I proceed?
>>
>> I have setup a thread to kill the calls when they are taking to much time
>>
>> Thanks,
>>
>> JM
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>>
>

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


Mime
View raw message