Package org.miaixz.bus.core.xyz
Class RetryKit
java.lang.Object
org.miaixz.bus.core.xyz.RetryKit
重试工具类
自定义功能请使用
RetryableTask类- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidofException(Runnable run, long maxAttempts, Duration delay, Runnable recover, Class<? extends Throwable>... exs) 根据异常信息进行重试 没有返回值,重试执行方法static <T> TofException(Supplier<T> sup, long maxAttempts, Duration delay, Supplier<T> recover, Class<? extends Throwable>... exs) 根据异常信息进行重试 有返回值,重试执行方法static voidofPredicate(Runnable run, long maxAttempts, Duration delay, Supplier<Void> recover, BiPredicate<Void, Throwable> predicate) 根据自定义结果进行重试 没有返回值,重试执行方法static <T> TofPredicate(Supplier<T> sup, long maxAttempts, Duration delay, Supplier<T> recover, BiPredicate<T, Throwable> predicate) 根据异常信息进行重试 有返回值,重试执行方法
-
Constructor Details
-
RetryKit
public RetryKit()
-
-
Method Details
-
ofException
public static void ofException(Runnable run, long maxAttempts, Duration delay, Runnable recover, Class<? extends Throwable>... exs) 根据异常信息进行重试 没有返回值,重试执行方法- Parameters:
run- 执行方法maxAttempts- 最大的重试次数delay- 重试间隔recover- 达到最大重试次数后执行的备用方法,入参是重试过程中的异常exs- 指定的异常类型需要重试
-
ofException
public static <T> T ofException(Supplier<T> sup, long maxAttempts, Duration delay, Supplier<T> recover, Class<? extends Throwable>... exs) 根据异常信息进行重试 有返回值,重试执行方法- Type Parameters:
T- 结果类型- Parameters:
sup- 执行方法maxAttempts- 最大的重试次数delay- 重试间隔recover- 达到最大重试次数后执行的备用方法,入参是重试过程中的异常exs- 指定的异常类型需要重试- Returns:
- 执行结果
-
ofPredicate
public static void ofPredicate(Runnable run, long maxAttempts, Duration delay, Supplier<Void> recover, BiPredicate<Void, Throwable> predicate) 根据自定义结果进行重试 没有返回值,重试执行方法- Parameters:
run- 执行方法maxAttempts- 最大的重试次数delay- 重试间隔recover- 达到最大重试次数后执行的备用方法,入参是重试过程中的异常predicate- 自定义重试条件
-
ofPredicate
public static <T> T ofPredicate(Supplier<T> sup, long maxAttempts, Duration delay, Supplier<T> recover, BiPredicate<T, Throwable> predicate) 根据异常信息进行重试 有返回值,重试执行方法- Type Parameters:
T- 结果类型- Parameters:
sup- 执行方法maxAttempts- 最大的重试次数delay- 重试间隔recover- 达到最大重试次数后执行的备用方法,入参是重试过程中的异常predicate- 自定义重试条件- Returns:
- 执行结果
-