Class RetryUtils

java.lang.Object
org.jppf.utils.RetryUtils

public class RetryUtils extends Object
Utility methods for retrying a callback that throws an exception, until it succeeds or either a maximum number of attempts is reached or a timeout expires.
Since:
6.0
Author:
Laurent Cohen
  • Constructor Details

    • RetryUtils

      public RetryUtils()
  • Method Details

    • runWithRetry

      public static <T> T runWithRetry(int maxTries, long retryDelay, Callable<T> callable) throws Exception
      Execute the specified Callable in a retry loop.
      Type Parameters:
      T - the return type of the Callable.
      Parameters:
      maxTries - the maximum number of attempts to execute the Callable.
      retryDelay - the delay between two attempts.
      callable - the Callable to execute.
      Returns:
      the return value of the first successful execution of the Callable.
      Throws:
      Exception - if after maxRetries the Callable threw an exception.
    • runWithRetryTimeout

      public static <T> T runWithRetryTimeout(long timeout, long retryDelay, Callable<T> callable) throws Exception
      Execute the specified Callable in a retry loop.
      Type Parameters:
      T - the return type of the Callable.
      Parameters:
      timeout - the maximum tim during which to attempt, in millis.
      retryDelay - the delay between two attempts.
      callable - the Callable to execute.
      Returns:
      the return value of the first successful execution of the Callable.
      Throws:
      Exception - if after maxRetries the Callable threw an exception.
    • runWithRetryTimeout

      public static <T> T runWithRetryTimeout(long timeout, long retryDelay, Runnable runnable) throws Exception
      Execute the specified Runnable in a retry loop.
      Type Parameters:
      T - the return type of the Callable.
      Parameters:
      timeout - the maximum tim during which to attempt, in millis.
      retryDelay - the delay between two attempts.
      runnable - the Runnable to execute.
      Returns:
      the return value of the first successful execution of the Callable.
      Throws:
      Exception - if after maxRetries the Callable threw an exception.