I have a Spring Boot based application and using RestTemplate
for sending HTTP requests. Some endpoints to which the application sends requests respond very slow, but some should respond fast. When the service using RestTemplate
is used by ~20 threads in parallel then RestTemplate happens to hang and wait for something (some requests to fast endpoints are executed much slower than they should).
When I switched to Jersey HTTP client the problem disappeared, so it must be something with RestTemplate
itself.
I create the bean with RestTemplateBuilder
:
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
}
And use exchange
method for sending requests:
ResponseEntity<Void> result = restTemplate.exchange(url, HttpMethod.POST, request, Void.class);
Does anyone know why RestTemplate can behave in such a way?