hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From whybert <whyb...@163.com>
Subject Re:Re: A question about ConnectTimeout and SoTimeout
Date Mon, 25 Aug 2014 12:13:31 GMT
Thank you for your reply.


I think I just set the IOReactorConfig.setConnectTimeout(). This is my code (HttpAsyncClient4.0.2)
:


public class Test {
    public static void main(String[] args) throws InterruptedException,
            IOException, TimeoutException {
        IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
                .setConnectTimeout(2000).build();
        ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(
                ioReactorConfig);
        PoolingNHttpClientConnectionManager cm = new PoolingNHttpClientConnectionManager(
                ioReactor);
        CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
                .setConnectionManager(cm).build();
        httpclient.start();
        HttpGet request = new HttpGet("http://1.1.1.1/");
        Future<HttpResponse> future = httpclient.execute(request, null);
        long timeSt = new Date().getTime();
        try {
            HttpResponse response = future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            System.out.println(new Date().getTime() - timeSt);
            System.out.println(e.getMessage());
        }
        httpclient.close();
    }
}


It took 21 seconds to get a ConnectException while the ConnectTimeout was 2 seconds. 
Could you help me to look at this problem? Thanks!


Regards,
Whybert


At 2014-08-25 07:42:28, "Oleg Kalnichevski" <olegk@apache.org> wrote:
>On Sun, 2014-08-24 at 12:07 +0800, whybert wrote:
>> Hi,
>>      I am evaluating HTTP Async client and have following questions.
>> 
>> 
>> There are two ways to set ConnectTimeout and SoTimeout in official examples: 
>>         // Create I/O reactor configuration
>>         IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
>>                 .setIoThreadCount(Runtime.getRuntime().availableProcessors())
>>                 .setConnectTimeout(30000)
>>                 .setSoTimeout(30000)
>>                 .build();
>>         RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig)
>>                 .setSocketTimeout(5000)
>>                 .setConnectTimeout(5000)
>>                 .setConnectionRequestTimeout(5000)
>>                 .build();
>> What's the difference between the two ways? 
>
>Consider I/O reactor configuration to be global defaults some which can
>overridden at the request level.
>
>> And I find the IOReactorConfig.custom().setConnectTimeout() doesn't seem to work.
>
>I can see the default connecting I/O reactor impl clearly making use of
>this parameter. Could you please make sure you are not overriding the
>I/O reactor defaults at the request level?
>
>Oleg
>
>
>
>---------------------------------------------------------------------
>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