Class RetryUtils

  • All Implemented Interfaces:

    
    public final class RetryUtils
    
                        

    Utility class for retrying actions.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public final class RetryUtils.RetryPolicy

      This class encapsulates a retry policy.

    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      static RetryUtils.RetryPolicy.Builder retryPolicyBuilder() This method returns a RetryPolicy.Builder.
      static <T> T withRetry(Callable<T> action, int maxAttempts) This method attempts to execute a given action up to a specified number of times with a 1-second delay.
      static <T> T withRetry(Callable<T> action) This method attempts to execute a given action up to a specified number of times with a 1-second delay.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • withRetry

         static <T> T withRetry(Callable<T> action, int maxAttempts)

        This method attempts to execute a given action up to a specified number of times with a 1-second delay. If the action fails on all attempts, it throws a RuntimeException.

        Parameters:
        action - The action to be executed.
        maxAttempts - The maximum number of attempts to execute the action.
        Returns:

        The result of the action if it is successful.

      • withRetry

         static <T> T withRetry(Callable<T> action)

        This method attempts to execute a given action up to a specified number of times with a 1-second delay. If the action fails on all attempts, it throws a RuntimeException.

        Parameters:
        action - The action to be executed.
        Returns:

        The result of the action if it is successful.