SoFunction
Updated on 2025-03-09

Solve the problem of slow response speed for the first request of RestTemplate

RestTemplate's first request is slow to respond

Using RestTemplate to request WeChat interface found that the first request took about 8 seconds. After checking the JDK information, I found that it was an IPv6 problem.

Just add -.preferIPv4Stack=true at startup.

Timeout setting for RestTemplate request

//Set the timeout time of rest request// SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
// (20000);
// (30000);
// restTemplate = new RestTemplate(simpleClientHttpRequestFactory);

The above is personal experience. I hope you can give you a reference and I hope you can support me more.