Should I install ConnectionRequestTimeout on Apache HttpClient if I do not use a custom connection manager?

I am using Apache RequestConfig to configure some timeouts on my HttpClient .

 RequestConfig config = RequestConfig.custom() .setConnectTimeout(timeout) .setSocketTimeout(timeout) .setConnectionRequestTimeout(timeout) // Can I leave this out.. .build(); CloseableHttpClient httpClient = HttpClients.custom() //.setConnectionManager(connectionManager) // ..if I don't use this .setDefaultRequestConfig(config) .build(); 

Does it make sense to call setConnectionRequestTimeout(timeout) even if I don't have a custom connection manager / pool manager?

As far as I understand, setConnectionRequestTimeout(timeout) used to set the connection timeout from the connection manager / pool.

Please note that I do not install the connection manager on the HttpClient (see comment).

+6
source share
2 answers

connectionRequestTimeout happens when you have a connection pool, and they are all busy, not allowing the connection manager to give you a connection to complete the request.

So the answer to your question is:

Does it make sense to call setConnectionRequestTimeout (timeout) even I don't have a custom connection manager / pool manager?

- YES.

This is because the standard implementation has an internal connection pool. So yes, it makes sense to specify a connection request timeout. This is actually a good, safe practice.

+4
source

Isuru's answer is mostly correct. The default connection manager is PoolingHttpClientConnectionManager .
However, by default it will only have one connection. If you use HttpClient synchronously from the same stream, you will never encounter a situation in which the ConnectionRequestTimeout effect takes effect.
If you use HttpClient from multiple threads, you might want to install it, but you probably also want to increase the pool size, by the way.
For single-threaded use, httpclient is safe to leave it.

+5
source

Source: https://habr.com/ru/post/980448/


All Articles