Class RetryTemplate

java.lang.Object
org.springframework.retry.support.RetryTemplate
All Implemented Interfaces:
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.

Author:
Rob Harrop, Dave Syer, Gary Russell, Artem Bilan, Josh Long, Aleksandr Shamukov
  • Field Details

    • logger

      protected final org.apache.commons.logging.Log logger
  • Constructor Details

    • RetryTemplate

      public RetryTemplate()
  • Method Details