Class RetryUtil

java.lang.Object
cn.toint.oktool.util.RetryUtil

public class RetryUtil extends Object
重试工具
Author:
Toint
  • Constructor Details

    • RetryUtil

      public RetryUtil()
  • Method Details

    • execute

      public static <R> R execute(Callable<R> callable)
      重试机制
      Type Parameters:
      R - 返回类型
      Parameters:
      callable - 执行方法
      Returns:
      方法执行结果
      Throws:
      RetryException - 重试失败
    • execute

      @SafeVarargs public static <R> R execute(Callable<R> callable, int retrySize, Duration intervalTime, Class<? extends Throwable>... exceptionClass)
      重试机制
      Type Parameters:
      R - 返回类型
      Parameters:
      callable - 执行方法
      retrySize - 重试次数 (不包含首次执行, 小于1表示不重试, 但无论如何方法会执行1次)
      intervalTime - 间隔时间 (null 或 小于等于0, 表示立刻重试不会等待)
      exceptionClass - 需要重试的异常类型 (默认 Exception)
      Returns:
      方法执行结果
      Throws:
      RetryException - 重试失败
    • execute

      @SafeVarargs public static <R> R execute(Callable<R> callable, int retrySize, Duration intervalTime, boolean printStackTrace, Class<? extends Throwable>... exceptionClass)
      重试机制
      Type Parameters:
      R - 返回类型
      Parameters:
      callable - 执行方法
      retrySize - 重试次数 (不包含首次执行, 小于1表示不重试, 但无论如何方法会执行1次)
      intervalTime - 间隔时间 (null 或 小于等于0, 表示立刻重试不会等待)
      printStackTrace - 重试时是否打印异常信息 (false 不打印)
      exceptionClass - 需要重试的异常类型 (默认 Exception)
      Returns:
      方法执行结果
      Throws:
      RetryException - 重试失败
    • execute

      public static <R> R execute(Callable<R> callable, Collection<RetryPolicy> retryPolicies)
      重试机制
      Type Parameters:
      R - 返回类型
      Parameters:
      callable - 执行方法
      retryPolicies - 重试策略
      Returns:
      方法执行结果
      Throws:
      RetryException - 重试失败