RestTemplate ResourceAccessException :Read Timed Out

  Kiến thức lập trình

I have a SpringBoot_3.2.1/JDK17/Tomcat10 application where I am using a RestTemplate.

At some point it makes a call :

RestTemplate template = new RestTemplate();
template.exchange( ,,,, );

My call executes a storedProc that runs longer than 3 minutes. And in exactly 3 minutes I am getting an exception:

org.springframework.web.client.ResourceAccessException : I/O Error on POST request for <MyURL> : Read Timed out
....

Caused by : java.netSocketTimeoutException : Read Timed out

I tried to pass arguments to JVM :

-Dsun.net.client.defaultConnectionTimeout=600000 
-Dsun.net.client.defaultReadTimeout=600000 

I also tried to set it programmatically :

RestTemplate restTemplate = new RestTemplate(getClientHttpRequestFactory());

//Override timeouts in request factory
private SimpleClientHttpRequestFactory getClientHttpRequestFactory() {

    SimpleClientHttpRequestFactory clientHttpRequestFactory  = new SimpleClientHttpRequestFactory();
    clientHttpRequestFactory.setConnectTimeout(600000);
    clientHttpRequestFactory.setReadTimeout(600000);
    return clientHttpRequestFactory;
}

I am still getting a Read Timed out Exception after exactly 3 minutes. Two questions :

  1. Where is this 3 minute time out is set?
  2. How can I increase the timeout so the application doesn’t fail?

we have Red Hat Linux version 9.4

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT