类 RetryUtil
- java.lang.Object
-
- net.risesoft.api.utils.jdbc.RetryUtil
-
public final class RetryUtil extends Object
-
-
构造器概要
构造器 构造器 说明 RetryUtil()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static <T> TasyncExecuteWithRetry(Callable<T> callable, int retryTimes, long sleepTimeInMilliSecond, boolean exponential, long timeoutMs, ThreadPoolExecutor executor)在外部线程执行并且重试。static ThreadPoolExecutorcreateThreadPoolExecutor()创建异步执行的线程池。static <T> TexecuteWithRetry(Callable<T> callable, int retryTimes, long sleepTimeInMilliSecond, boolean exponential)重试次数工具方法.static <T> TexecuteWithRetry(Callable<T> callable, int retryTimes, long sleepTimeInMilliSecond, boolean exponential, List<Class<?>> retryExceptionClasss)重试次数工具方法.
-
-
-
方法详细资料
-
executeWithRetry
public static <T> T executeWithRetry(Callable<T> callable, int retryTimes, long sleepTimeInMilliSecond, boolean exponential) throws Exception
重试次数工具方法.- 类型参数:
T- 返回值类型- 参数:
callable- 实际逻辑retryTimes- 最大重试次数(>1)sleepTimeInMilliSecond- 运行失败后休眠对应时间再重试exponential- 休眠时间是否指数递增- 返回:
- 经过重试的callable的执行结果
- 抛出:
Exception
-
executeWithRetry
public static <T> T executeWithRetry(Callable<T> callable, int retryTimes, long sleepTimeInMilliSecond, boolean exponential, List<Class<?>> retryExceptionClasss) throws Exception
重试次数工具方法.- 类型参数:
T- 返回值类型- 参数:
callable- 实际逻辑retryTimes- 最大重试次数(>1)sleepTimeInMilliSecond- 运行失败后休眠对应时间再重试exponential- 休眠时间是否指数递增retryExceptionClasss- 出现指定的异常类型时才进行重试- 返回:
- 经过重试的callable的执行结果
- 抛出:
Exception
-
asyncExecuteWithRetry
public static <T> T asyncExecuteWithRetry(Callable<T> callable, int retryTimes, long sleepTimeInMilliSecond, boolean exponential, long timeoutMs, ThreadPoolExecutor executor) throws Exception
在外部线程执行并且重试。每次执行需要在timeoutMs内执行完,不然视为失败。 执行异步操作的线程池从外部传入,线程池的共享粒度由外部控制。比如,HttpClientUtil共享一个线程池。 限制条件:仅仅能够在阻塞的时候interrupt线程- 类型参数:
T- 返回值类型- 参数:
callable- 实际逻辑retryTimes- 最大重试次数(>1)sleepTimeInMilliSecond- 运行失败后休眠对应时间再重试exponential- 休眠时间是否指数递增timeoutMs- callable执行超时时间,毫秒executor- 执行异步操作的线程池- 返回:
- 经过重试的callable的执行结果
- 抛出:
Exception
-
createThreadPoolExecutor
public static ThreadPoolExecutor createThreadPoolExecutor()
创建异步执行的线程池。特性如下: core大小为0,初始状态下无线程,无初始消耗。 max大小为5,最多五个线程。 60秒超时时间,闲置超过60秒线程会被回收。 使用SynchronousQueue,任务不会排队,必须要有可用线程才能提交成功,否则会RejectedExecutionException。- 返回:
- 线程池
-
-