我给了连接超时5000毫秒(5秒),但实际上需要10127毫秒(10.127秒)
如果connectiontimeout = 10000毫秒(10秒),则连接超时将花费20032毫秒(20秒)
下面是我尝试过的代码。
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));
}
}