Class RetryUtils

java.lang.Object
dk.gtz.graphedit.util.RetryUtils

public final class RetryUtils extends Object
Utility functions for retrying actions multiple times.
  • Method Details

    • tryTimes

      public static <T> T tryTimes(int maxAttempts, int sleepMillis, Supplier<T> f)
      Try an action until it returns a value or until a set amount of attempts failed.
      Type Parameters:
      T - The return type that the function should return.
      Parameters:
      maxAttempts - Maximum amount of times to try
      sleepMillis - Amount of time to wait between failed attempts
      f - The supplier function to try
      Returns:
      The return value of the supplier function f
      Throws:
      RuntimeException - if too many attempts happenned
    • sleep

      public static void sleep(int milliseconds)
      Sleep for a set amount of milliseconds. If interrupted, simply return.
      Parameters:
      milliseconds - The length of time to wait in milliseconds