The socket timeout is just the maximum time to wait between TCP packets
from the server arriving. The server's response will arrive packet by
packet, so if two minutes (120000) elapse without receiving a packet, then
the socket timeout exception will get thrown.

However, if the server is slow but can emit at least one packet every two
minutes, it won't timeout, even if it takes hours to get a complete
response.

If what you want to do is "throw an exception unless I get a complete
response (all packets) within two minutes of issuing the request", then
this is not a feature supported by HttpClient as-is, and you'll have to
manage it yourself.

One possibility is to get an ExecutorService and submit() the request
execution there, receiving back a Future in the calling thread. You can
then do Future.get(), using the variant that takes a timeout.

Hope that helps,
Jon


On Tue, Jul 29, 2014 at 10:47 PM, 风 <[email protected]> wrote:

> Thanks for Oleg's answer.
> But I don't really know what you mean. Here is my understand.
>
>
> when call httpclient.execute(), it connect the server successfully, and
> read response from the server. but the server's data transfer is so slow,
> so httpclient blocking to read the response so long time. ‍
>
>
> Now if i call the function already : setSocketTimeout(120000), but the
> socket timeout will not ‍effective at all. the httpclient still blocking to
> wait response.
>
>
> Is this right?
>
>
> thanks!‍
>
>
>
>
> ------------------ 原始邮件 ------------------
> 发件人: "Oleg Kalnichevski";<[email protected]>;
> 发送时间: 2014年7月28日(星期一) 下午5:19
> 收件人: "HttpClient User Discussion"<[email protected]>;
>
> 主题: Re: A question about the timeout of httpclient
>
>
>
> On Mon, 2014-07-28 at 15:22 +0800, 风 wrote:
> > i have set the timeout of the httpclient, code is here:
> > RequestConfig config = RequestConfig.custom()
> >                                   .setSocketTimeout(120000)
> >                                   .setConnectTimeout(120000)
> >                                   .setConnectionRequestTimeout(120000)
> >                                   .build();
> > httpclient = HttpClients.custom()
> >                               .setDefaultRequestConfig(config)
> >                               .setRedirectStrategy(myRedirectStrategy)
> >                               .setRoutePlanner(routePlanner)
> >                               .build();‍
> >
> >
> >
> > But when i call httpclient.execute(), it will still block here so long
> time great than 120000 milisecond.
> > why the timeout is not effective? please help!
>
> This is because socket timeout defines a maximum period of inactivity
> between two consecutive read operations, and not an absolute operation
> deadline.
>
> Hope this helps
>
> Oleg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]

Reply via email to