public class RetryUtil extends Object
RetryableTask类RetryableTask| Constructor and Description |
|---|
RetryUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
ofException(Runnable run,
long maxAttempts,
Duration delay,
Runnable recover,
Class<? extends Throwable>... exs)
根据异常信息进行重试
没有返回值,重试执行方法
|
static <T> T |
ofException(Supplier<T> sup,
long maxAttempts,
Duration delay,
Supplier<T> recover,
Class<? extends Throwable>... exs)
根据异常信息进行重试
有返回值,重试执行方法
|
static void |
ofPredicate(Runnable run,
long maxAttempts,
Duration delay,
Supplier<Void> recover,
BiPredicate<Void,Throwable> predicate)
根据自定义结果进行重试
没有返回值,重试执行方法
|
static <T> T |
ofPredicate(Supplier<T> sup,
long maxAttempts,
Duration delay,
Supplier<T> recover,
BiPredicate<T,Throwable> predicate)
根据异常信息进行重试
有返回值,重试执行方法
|
public static void ofException(Runnable run, long maxAttempts, Duration delay, Runnable recover, Class<? extends Throwable>... exs)
run - 执行方法maxAttempts - 最大的重试次数delay - 重试间隔recover - 达到最大重试次数后执行的备用方法,入参是重试过程中的异常exs - 指定的异常类型需要重试public static <T> T ofException(Supplier<T> sup, long maxAttempts, Duration delay, Supplier<T> recover, Class<? extends Throwable>... exs)
T - 结果类型sup - 执行方法maxAttempts - 最大的重试次数delay - 重试间隔recover - 达到最大重试次数后执行的备用方法,入参是重试过程中的异常exs - 指定的异常类型需要重试public static void ofPredicate(Runnable run, long maxAttempts, Duration delay, Supplier<Void> recover, BiPredicate<Void,Throwable> predicate)
run - 执行方法maxAttempts - 最大的重试次数delay - 重试间隔recover - 达到最大重试次数后执行的备用方法,入参是重试过程中的异常predicate - 自定义重试条件public static <T> T ofPredicate(Supplier<T> sup, long maxAttempts, Duration delay, Supplier<T> recover, BiPredicate<T,Throwable> predicate)
T - 结果类型sup - 执行方法maxAttempts - 最大的重试次数delay - 重试间隔recover - 达到最大重试次数后执行的备用方法,入参是重试过程中的异常predicate - 自定义重试条件Copyright © 2025. All rights reserved.