Package cn.dinodev.spring.commons.utils
Class TaskUtils
java.lang.Object
cn.dinodev.spring.commons.utils.TaskUtils
- Author:
- Cody Lu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void无参数,无返回的static void无参数,无返回的static <R> Promise<R>exec(Callable<R> task, Predicate<R> checker, int attempts, Class<? extends RuntimeException>... throwOutExceptions) 无参数,有返回的任务调用static <R> Promise<R>exec(Callable<R> task, Predicate<R> checker, int attempts, Duration nap, Class<? extends RuntimeException>... throwOutExceptions) 无参数,有返回的任务调用<T,U> void exec(BiConsumer<T, U> task, T paramFirst, U paramSecond, int attempts) task接受两个参数,无返回值<T,U> void exec(BiConsumer<T, U> task, T paramFirst, U paramSecond, int attempts, Duration nap) task接受两个参数,无返回值<T,U, R> Promise<R> exec(BiFunction<T, U, R> task, T paramFirst, U paramSecond, Predicate<R> checker, int attempts, Class<? extends RuntimeException>... throwOutExceptions) task接受两个参数,并返回执行结果<T,U, R> Promise<R> exec(BiFunction<T, U, R> task, T paramFirst, U paramSecond, Predicate<R> checker, int attempts, Duration nap, Class<? extends RuntimeException>... throwOutExceptions) task接受两个参数,并返回执行结果static <T> voidtask接受一个参数,无返回值static <T> voidtask接受一个参数,无返回值<T,R> Promise<R> exec(Function<T, R> task, T param, Predicate<R> checker, int attempts, Class<? extends RuntimeException>... throwOutExceptions) task接受一个参数,并返回执行结果<T,R> Promise<R> exec(Function<T, R> task, T param, Predicate<R> checker, int attempts, Duration nap, Class<? extends RuntimeException>... throwOutExceptions) task接受一个参数,并返回执行结果static boolean线程休息一会
-
Constructor Details
-
TaskUtils
public TaskUtils()
-
-
Method Details
-
exec
无参数,无返回的- Parameters:
task- 任务attempts- 重试次数
-
exec
无参数,无返回的- Parameters:
task- 任务attempts- 重试次数nap- 重试间隔时长
-
exec
task接受一个参数,无返回值- Type Parameters:
T- 参数类型- Parameters:
task- 任务param- 传给任务的参数attempts- 重试次数
-
exec
task接受一个参数,无返回值- Type Parameters:
T- 参数类型- Parameters:
task- 任务param- 传给任务的参数attempts- 重试次数nap- 重试间隔时长
-
exec
task接受两个参数,无返回值- Type Parameters:
T- 第一个参数类型U- 第二个参数类型- Parameters:
task- 任务paramFirst- 第一个参数paramSecond- 第二个参数attempts- 重试次数
-
exec
public <T,U> void exec(BiConsumer<T, U> task, T paramFirst, U paramSecond, int attempts, Duration nap) task接受两个参数,无返回值- Type Parameters:
T- 第一个参数类型U- 第二个参数类型- Parameters:
task- 任务paramFirst- 第一个参数paramSecond- 第二个参数attempts- 重试次数nap- 重试间隔时长
-
exec
@SafeVarargs public static <R> Promise<R> exec(Callable<R> task, Predicate<R> checker, int attempts, Class<? extends RuntimeException>... throwOutExceptions) 无参数,有返回的任务调用- Type Parameters:
R- 返回值类型- Parameters:
task- 任务checker- 检查task返回值是否符合要求,不符合则重试attempts- 重试次数throwOutExceptions- 直接抛出的异常的类型
-
exec
@SafeVarargs public static <R> Promise<R> exec(Callable<R> task, Predicate<R> checker, int attempts, Duration nap, Class<? extends RuntimeException>... throwOutExceptions) 无参数,有返回的任务调用- Type Parameters:
R- 返回值类型- Parameters:
task- 任务checker- 检查task返回值是否符合要求,不符合则重试attempts- 重试次数, 1表示最多执行一次nap- 重试间隔时长throwOutExceptions- 直接抛出的异常的类型
-
exec
@SafeVarargs public <T,R> Promise<R> exec(Function<T, R> task, T param, Predicate<R> checker, int attempts, Class<? extends RuntimeException>... throwOutExceptions) task接受一个参数,并返回执行结果- Type Parameters:
T- 参数类型R- 返回值类型- Parameters:
task- 任务param- 传给异步任务的参数checker- 检查task返回值是否符合要求,不符合则重试attempts- 重试次数, 1表示最多执行一次throwOutExceptions- 直接抛出的异常的类型- Returns:
-
exec
@SafeVarargs public <T,R> Promise<R> exec(Function<T, R> task, T param, Predicate<R> checker, int attempts, Duration nap, Class<? extends RuntimeException>... throwOutExceptions) task接受一个参数,并返回执行结果- Type Parameters:
T- 参数类型R- 返回值类型- Parameters:
task- 任务param- 传给异步任务的参数checker- 检查task返回值是否符合要求,不符合则重试attempts- 重试次数, 1表示最多执行一次nap- 重试间隔时长throwOutExceptions- 直接抛出的异常的类型- Returns:
-
exec
@SafeVarargs public <T,U, Promise<R> execR> (BiFunction<T, U, R> task, T paramFirst, U paramSecond, Predicate<R> checker, int attempts, Class<? extends RuntimeException>... throwOutExceptions) task接受两个参数,并返回执行结果- Type Parameters:
T- 第一个参数类型U- 第二个参数类型R- 返回结果类型- Parameters:
task- 任务paramFirst- 第一个参数paramSecond- 第二个参数checker- 检查task返回值是否符合要求,不符合则重试attempts- 重试次数, 1表示最多执行一次throwOutExceptions- 直接抛出的异常的类型- Returns:
-
exec
@SafeVarargs public <T,U, Promise<R> execR> (BiFunction<T, U, R> task, T paramFirst, U paramSecond, Predicate<R> checker, int attempts, Duration nap, Class<? extends RuntimeException>... throwOutExceptions) task接受两个参数,并返回执行结果- Type Parameters:
T- 第一个参数类型U- 第二个参数类型R- 返回结果类型- Parameters:
task- 任务paramFirst- 第一个参数paramSecond- 第二个参数checker- 检查task返回值是否符合要求,不符合则重试attempts- 重试次数, 1表示最多执行一次nap- 重试间隔时长throwOutExceptions- 直接抛出的异常的类型- Returns:
-
nap
线程休息一会- Parameters:
nap- 时间长度- Returns:
- true:如果没被打断,false:如果被打断。
-