Dattatray Satpute
Dattatray Satpute

Reputation: 263

Httpclient 4.5 taking double time for closing the http connection

I have given the connectiontimeout 5000 milliseconds(5 second) but actually it takes 10127 milliseconds(10.127 second)

if connectiontimeout=10000 milliseconds(10 second) then it is taking 20032 milliseconds(20 second) for connection time out

below is the code which i tried.

public static void getTest() 
{
     long start=0;

     try {

            CloseableHttpClient httpClient = HttpClients.createDefault();
            HttpGet httpGet = new HttpGet("http://testing url");
            RequestConfig config=null;
             config = RequestConfig.custom()
                     .setConnectTimeout(5000)
                     .setConnectionRequestTimeout(5000)
                     .setSocketTimeout(5000)
                     .build();
             httpGet.setConfig(config);
             start = System.currentTimeMillis();
             httpClient.execute(httpGet);
    } catch (Exception e) {
        long end=System.currentTimeMillis();
        System.out.println("total time in Milliseconds:="+(end-start));
    }

}

Upvotes: 0

Views: 523

Answers (1)

Amila Liyanage
Amila Liyanage

Reputation: 31

The reason is unsuccessful HTTP POST request will be automatically re-sent to the server. Unsuccessful post means, in this case, the server did not send a valid HTTP response or an IOException occurred and HTTP PostRetry default value is true in JVM. There are servral ways to prevent from silent HttpRetry please refer below-mentioned table.

enter image description here

That's the main reason for doubled the exact timeout.

Upvotes: 1

Related Questions