hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen J. Butler" <stephen.but...@gmail.com>
Subject Re: Right way to timeout
Date Mon, 17 Dec 2012 03:07:15 GMT
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
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message