13

When building a CloseableHttpClient in Apache HttpClient 4.3, I can use

SocketConfig.custom().setSoTimeout(soTimeout).build()

and send it to the setDefaultSocketConfig() method of my connection manager.

I can also use

RequestConfig.custom().setSocketTimeout(socketTimeout).build()

and send it to the setDefaultRequestConfig() method of my http client builder.

Will these have the same end effect or different end effects?

1 Answer 1

5

Socket timeout in SocketConfig represents the default value applied to newly created connections. This value can be overwritten for individual requests by setting a non zero value of socket timeout in RequestConfig.

6
  • So what happens if there's both a SocketConfig and a default RequestConfig? Mar 28, 2014 at 20:54
  • SocketConfig applies only when new sockets are created. RequestConfig socket timeout value always overwrites that set at construction time.
    – ok2c
    Mar 29, 2014 at 10:53
  • 2
    To state in other words, it appears that SocketConfig's socket timeout is still used for initial socket creation regardless of RequestConfig's socket timeout. We discovered an issue that appears to require socket timeouts on both SocketConfig and RequestConfig.
    – Stano
    Jul 29, 2014 at 16:28
  • 2
    The socketTimeout value is seconds / milliseconds ? is quite unclear to me from the java docs, as it is not specified. Mar 7, 2016 at 10:13
  • 1
    @RaduToader Socket timeouts are always in milliseconds.
    – user207421
    Jan 22, 2018 at 1:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.