类 RetryTemplate

java.lang.Object
infra.retry.support.RetryTemplate
所有已实现的接口:
RetryOperations

public class RetryTemplate extends Object implements RetryOperations
Template class that simplifies the execution of operations with retry semantics.

Retryable operations are encapsulated in implementations of the RetryCallback interface and are executed using one of the supplied execute methods.

By default, an operation is retried if is throws any Exception or subclass of Exception. This behaviour can be changed by using the setRetryPolicy(RetryPolicy) method.

Also by default, each operation is retried for a maximum of three attempts with no back off in between. This behaviour can be configured using the setRetryPolicy(RetryPolicy) and setBackOffPolicy(BackOffPolicy) properties. The BackOffPolicy controls how long the pause is between each individual retry attempt.

A new instance can be fluently configured via builder(), e.g:

 
 RetryTemplate.builder()
                 .maxAttempts(10)
                 .fixedBackoff(1000)
                 .build();
 
See RetryTemplateBuilder for more examples and details.

This class is thread-safe and suitable for concurrent access when executing operations and when performing configuration changes. As such, it is possible to change the number of retries on the fly, as well as the BackOffPolicy used and no in progress retryable operations will be affected.

从以下版本开始:
4.0
作者:
Rob Harrop, Dave Syer, Gary Russell, Artem Bilan, Josh Long, Aleksandr Shamukov, Harry Yang