Solve the problem of slow response speed of RestTemplate's first request
- 2021-12-04 18:53:27
- OfStack
Directory RestTemplate First Request Slow Response Problem RestTemplate Request Timeout Setting
Slow response speed of RestTemplate first request
Using the interface of RestTemplate to request WeChat, it was found that the first request took about 8 seconds. After consulting JDK data, it was found that it was IPv6
Simply add-Djava. net. preferIPv4Stack=true at startup.
Timeout settings for RestTemplate requests
// Settings rest Requested timeout
// SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
// simpleClientHttpRequestFactory.setConnectTimeout(20000);
// simpleClientHttpRequestFactory.setReadTimeout(30000);
// restTemplate = new RestTemplate(simpleClientHttpRequestFactory);