Class Retry

    • Constructor Detail

      • Retry

        public Retry()
    • Method Detail

      • execute

        public static int execute​(Runnable runnable,
                                  int attemptsCount,
                                  long intervalMillis)
        Runs the given runnable at most attemptsCount times until it passes, leaving intervalMillis milliseconds between the invocations. The runnable is reexecuted if it throws a RuntimeException or AssertionError.
        Parameters:
        runnable -
        attemptsCount - Total number of attempts to execute the runnable
        intervalMillis -
        Returns:
        Index of the first successful invocation, starting from 0.
      • executeWithBackoff

        public static int executeWithBackoff​(Retry.AdvancedRunnable runnable,
                                             int attemptsCount,
                                             int intervalBaseMillis)
        Runs the given runnable at most attemptsCount times until it passes, leaving some increasing random delay milliseconds between the invocations. It uses Exponential backoff + jitter algorithm to compute the delay. More details https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ The base for delay is specified by intervalBaseMillis number. The runnable is reexecuted if it throws a RuntimeException or AssertionError.
        Parameters:
        runnable -
        attemptsCount - Total number of attempts to execute the runnable
        intervalBaseMillis - base for the exponential backoff + jitter
        Returns:
        Index of the first successful invocation, starting from 0.
      • call

        public static <T> T call​(Retry.Supplier<T> supplier,
                                 int attemptsCount,
                                 long intervalMillis)
        Runs the given runnable at most attemptsCount times until it passes, leaving intervalMillis milliseconds between the invocations. The runnable is reexecuted if it throws a RuntimeException or AssertionError.
        Parameters:
        supplier -
        attemptsCount - Total number of attempts to execute the runnable
        intervalMillis -
        Returns:
        Value generated by the supplier.