Apache HttpClient CoreConnectionPNames.CONNECTION_TIMEOUT does nothing?

自古美人都是妖i 提交于 2019-12-01 06:20:14

The effective granularity of time-outs in all JVMs I have worked with is approximately 15-30ms. Even if the timeout is set to 1 socket I/O and connect requests often succeed if they take less than 15-30ms.

If you set the timeout of the HttpGet,instead of the HttpClient, it seems to work much better.

    HttpGet httpget = new HttpGet("http://www.apache.org/");

    RequestConfig Default = RequestConfig.DEFAULT;

    RequestConfig requestConfig = RequestConfig.copy(Default)
            .setSocketTimeout(5000)
            .setConnectTimeout(5000)
            .setConnectionRequestTimeout(5000)
            .build();
    httpget.setConfig(requestConfig);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!