Class DecorrelatedJitter

java.lang.Object
com.agentforge4j.util.retry.DecorrelatedJitter

public final class DecorrelatedJitter extends Object
Decorrelated-jitter backoff delay computation, shared by every retry loop in the codebase that needs to space out attempts against a transient failure.

The algorithm draws the next delay uniformly from [base, min(cap, 3 * lastDelay)), which spreads out concurrent retriers better than plain exponential backoff while still growing the delay across attempts. This class only computes the delay; callers own their own retry loop (attempt counting, which failures are retryable, whether to sleep at all) since that differs by caller.

  • Method Details

    • nextDelayMillis

      public static long nextDelayMillis(long baseMillis, long lastDelayMillis, long capMillis)
      Computes the next decorrelated-jitter delay.
      Parameters:
      baseMillis - the minimum delay (and the floor of every draw); non-negative
      lastDelayMillis - the delay used for the previous attempt (or the base, for the first retry); non-negative
      capMillis - the maximum delay this call may return
      Returns:
      a delay in milliseconds, at least baseMillis and at most capMillis