Default timeout for HttpComponent Client

柔情痞子 提交于 2019-12-03 10:41:18

According to the documentation, the http.socket.timeout parameter controls the SO_TIMEOUT value, and:

If this parameter is not set, read operations will not time out (infinite timeout).

Chandru

The accepted answer is not applicable for newer versions of HttpClient. Versions 4.3.X and above use the system default which is usually 60 secs.

Taken from HttpClient javadoc.

public int getSocketTimeout()
Defines the socket timeout (SO_TIMEOUT) in milliseconds, which is the timeout for waiting for data or, put differently, a maximum period inactivity between two consecutive data packets).
A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default).

Default: -1

For Apache HttpClient version 4.x upwards

int timeout = 5*60; // seconds (5 minutes)
RequestConfig config = RequestConfig.custom()
      .setConnectTimeout(timeout * 1000)
      .setConnectionRequestTimeout(timeout * 1000)
      .setSocketTimeout(timeout * 1000).build();
HttpClient httpClient = 
   HttpClientBuilder.create().setDefaultRequestConfig(config).build();

https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/config/RequestConfig.html#getSocketTimeout%28%29

A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default).

Default: -1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!