0

In order to configure RestTemplate I use the following configuration:

HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory(HttpClients.createDefault()); httpRequestFactory.setConnectTimeout(connectionTimeoutMs); httpRequestFactory.setConnectionRequestTimeout(readTimeoutMs); httpRequestFactory.setReadTimeout(readTimeoutMs); RestTemplate restTemplate = new RestTemplate(httpRequestFactory); 

I understand the purpose of connection and read timeouts. But I don't understand the purpose of connection request timeout. It also not clear from Javadoc what does it mean. Could you please explain it ?

1
  • 1
    It means that: the connection manager pool has this time to give you a valid connection to use in RestTemplate operations. A timeout value of zero is interpreted as an infinite timeout. Commented Aug 15, 2018 at 8:11

1 Answer 1

2

As the docs say :

Set the timeout in milliseconds used when requesting a connection from the connection manager using the underlying HttpClient.

It means the maximum amount of time you will allow to the connection manager to give you an available connection from its pool (so it has nothing to do with the RESTservice itself you'll reach).

To define a custom connection manager, you can use this :

CloseableHttpClient httpClientBuilder = HttpClientBuilder.create().setConnectionManager(...).build(); HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClientBuilder); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.