I have set 2000msec in Spring RedisTemplate in anticipation of timeout, but it may not work and processing may stall. Checking if it can be cleared by adding settings, if not, time out by yourself. .. ..
·Configured setConnectionRequestTimeout:10000msec setReadTimeout:2000msec
·add to? setConnectionRequestTimeout → I couldn't verify because I didn't have enough time
・ How to time out by yourself
This time it was Async (method using Spring @Async), so set return to Future
RetryTemplate
RetryTemplate retryTemplate = new RetryTemplate();
Map<Class<? extends Throwable>, Boolean> exceptions = Maps.newHashMap();
exceptions.put(TimeoutException.class, true);
retryTemplate.setRetryPolicy(new SimpleRetryPolicy(10, exceptions));
FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
backOffPolicy.setBackOffPeriod(10);
retryTemplate.setBackOffPolicy(backOffPolicy);
Future<T>(getResult)
Future<T> future = async.execute();
T result = retryTemplate.execute(new RetryCallback<T, TimeoutException>() {
@Override
public T doWithRetry(RetryContext context) throws TimeoutException {
if (future.isDone()) {
return future.get();
}
throw new TimeoutException();
}
});
reference ・ API https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.html
Recommended Posts