Package cn.xuanyuanli.core.util
Class Concurrents
java.lang.Object
cn.xuanyuanli.core.util.Concurrents
并发工具类
- Author:
- John Li
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ConcurrentMap<String, Object> 未来缓存protected static final org.slf4j.Logger日志记录器 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void等待某个任务执行完毕static void等待某个任务执行完毕static ThreadPoolExecutorcreateThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, int workQueueNum, String threadPrefixName) 创建一个通用的线程池static <T> TexecOfTimeout(Supplier<T> execBody, long timeout, Consumer<Exception> timeoutExceptionCall) 带超时设置的执行static <T> TexecuteTask(String key, Supplier<?> supplier) 多线程下执行相同任务,用此方法防止同一任务重复执行
-
Field Details
-
logger
protected static final org.slf4j.Logger logger日志记录器 -
FUTURE_CACHE
未来缓存
-
-
Constructor Details
-
Concurrents
public Concurrents()
-
-
Method Details
-
execOfTimeout
public static <T> T execOfTimeout(Supplier<T> execBody, long timeout, Consumer<Exception> timeoutExceptionCall) 带超时设置的执行- Type Parameters:
T- 泛型- Parameters:
execBody- 执行主体timeout- 超时时间,单位为毫秒timeoutExceptionCall- 超时异常的回调- Returns:
Concurrents
-
createThreadPoolExecutor
public static ThreadPoolExecutor createThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, int workQueueNum, String threadPrefixName) 创建一个通用的线程池- Parameters:
corePoolSize- 核心池大小maximumPoolSize- 最大池大小keepAliveTime- 维持时间unit- 货币workQueueNum- 全国矿工工会工作队列threadPrefixName- 线程前缀名字- Returns:
ThreadPoolExecutor
-
await
等待某个任务执行完毕- Parameters:
supplier- 任务是否完成,完成为trueintervalTime- 任务结果获取的间隔时间
-
await
等待某个任务执行完毕- Parameters:
supplier- 任务是否完成,完成为trueintervalTime- 任务结果获取的间隔时间maxRetryTime- 最大重试时间
-
executeTask
多线程下执行相同任务,用此方法防止同一任务重复执行- Type Parameters:
T- 泛型- Parameters:
key- 键supplier- 供应商- Returns:
Concurrents
-