Class RetryTemplateBuilder

java.lang.Object
org.springframework.retry.support.RetryTemplateBuilder

public class RetryTemplateBuilder extends Object
Fluent API to configure new instance of RetryTemplate. For detailed description of each builder method - see it's doc.

Examples:


 RetryTemplate.builder()
      .maxAttempts(10)
      .exponentialBackoff(100, 2, 10000)
      .retryOn(IOException.class)
      .traversingCauses()
      .build();

 RetryTemplate.builder()
      .fixedBackoff(10)
      .withinMillis(3000)
      .build();

 RetryTemplate.builder()
      .infiniteRetry()
      .retryOn(IOException.class)
      .uniformRandomBackoff(1000, 3000)
      .build();
 

The builder provides the following defaults:

  • retry policy: max attempts = 3 (initial + 2 retries)
  • backoff policy: no backoff (retry immediately)
  • exception classification: retry only on Exception and it's subclasses, without traversing of causes

The builder supports only widely used properties of RetryTemplate. More specific properties can be configured directly (after building).

Not thread safe. Building should be performed in a single thread. Also, there is no guarantee that all constructors of all fields are thread safe in-depth (means employing only volatile and final writes), so, in concurrent environment, it is recommended to ensure presence of happens-before between publication and any usage. (e.g. publication via volatile write, or other safe publication technique)

Since:
1.3
Author:
Aleksandr Shamukov, Artem Bilan, Kim In Hoi