Interface BackoffStrategy

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface BackoffStrategy
Strategy for computing delay between retry attempts.
Since:
5.4.0
Author:
Stefan Dragisic
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final BackoffStrategy
    Backoff strategy that applies no delay between retry attempts.
  • Method Summary

    Modifier and Type
    Method
    Description
    delay(int attempt)
    Computes the delay before the given retry attempt.
    Exponential backoff: min(base * 2^(attempt-1), max), clamped to max at large attempt counts so the factor/multiply can never overflow, go negative, or wrap.
    fixed(Duration delay)
    Fixed delay between every retry attempt.
    linear(Duration baseDelay)
    Linear backoff: baseDelay * attempt.
  • Field Details

    • NONE

      static final BackoffStrategy NONE
      Backoff strategy that applies no delay between retry attempts.
  • Method Details

    • fixed

      static BackoffStrategy fixed(Duration delay)
      Fixed delay between every retry attempt.
      Parameters:
      delay - constant delay duration.
      Returns:
      a backoff strategy with fixed delay.
    • linear

      static BackoffStrategy linear(Duration baseDelay)
      Linear backoff: baseDelay * attempt.
      Parameters:
      baseDelay - base delay multiplied by the attempt number.
      Returns:
      a backoff strategy with linearly increasing delay.
    • exponential

      static BackoffStrategy exponential(Duration base, Duration max)
      Exponential backoff: min(base * 2^(attempt-1), max), clamped to max at large attempt counts so the factor/multiply can never overflow, go negative, or wrap.
      Parameters:
      base - base delay for the first attempt.
      max - maximum delay cap.
      Returns:
      a backoff strategy with exponentially increasing delay.
    • delay

      Duration delay(int attempt)
      Computes the delay before the given retry attempt.
      Parameters:
      attempt - the retry attempt number (1-based).
      Returns:
      the duration to wait before executing the attempt.