8

I try to find out the timeout of the Apache HttpClient. The doc file* says that the default timeout for http connections is the "system default" timeout. But what is the "system default"? And how can I find out what the value for the "system default" timeout is set to?

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

Default: -1"(https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/config/RequestConfig.html#getConnectTimeout())

za3223340
  • 111
  • 2
  • 7
  • Possible duplicate of [Default timeout for HttpComponent Client](https://stackoverflow.com/questions/9734384/default-timeout-for-httpcomponent-client) – Michael Freidgeim Mar 14 '19 at 21:37

2 Answers2

1

System default in this particular situation means whatever socket timeout value set by the Java runtime. If the socket timeout configuration parameter is undefined, HttpClient makes no attempts to control the SO_TIMEOUT setting on connection sockets.

ok2c
  • 26,450
  • 5
  • 63
  • 71
0

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

AND

You can set default timeout by setParameter() method of HttpClient,

HttpClient httpclient = new HttpClient();
httpclient.getParams().setParameter("http.protocol.version",HttpVersion.HTTP_1_1);
httpclient.getParams().setParameter("http.socket.timeout", new Integer(1000));
httpclient.getParams().setParameter("http.protocol.content-charset", "UTF-8");
Prakash Jethava
  • 200
  • 1
  • 7
  • The doc says that "http.socket.timeout" is also undefined by default. So what's the default timeout of the HttpClient? Im pretty sure the reaction of the HttpClient can't be undefined(random). – za3223340 Mar 22 '18 at 17:49
  • This doesn't seem to compile, since HttpClient is an interface not a class. (and getParams() is deprecated) – DisplayName Mar 29 '18 at 17:07
  • You have to set parameter "http.socket.timeout" and give time. – Prakash Jethava Mar 29 '18 at 17:26
  • Is it possible to set this value globally, so that it affects all HttpClient instances? (used as default for all HttpClient instances, instead of the built-in default). Or does it have to be set on every HttpClient individually? – DisplayName Mar 30 '18 at 14:36