Merge branch 'V1.4'

# Conflicts:
#	src/main/java/com/jd/platform/async/executor/Async.java
#	src/main/java/com/jd/platform/async/wrapper/WorkerWrapper.java
This commit is contained in:
wuweifeng10
2021-03-05 17:53:55 +08:00
parent 49ddb57d5c
commit 4ea14f355b

View File

@@ -15,6 +15,9 @@ import java.util.stream.Collectors;
* @version 1.0
*/
public class Async {
/**
* 默认线程池
*/
private static final ThreadPoolExecutor COMMON_POOL =
new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors() * 2, 1024,
15L, TimeUnit.SECONDS,
@@ -70,10 +73,14 @@ public class Async {
return beginWork(timeout, COMMON_POOL, workerWrapper);
}
public static void beginWorkAsync(long timeout, IGroupCallback groupCallback, WorkerWrapper... workerWrapper) {
beginWorkAsync(timeout, COMMON_POOL, groupCallback, workerWrapper);
}
/**
* 异步执行,直到所有都完成,或失败后,发起回调
*/
public static void beginWorkAsync(long timeout, IGroupCallback groupCallback, WorkerWrapper... workerWrapper) {
public static void beginWorkAsync(long timeout, ExecutorService executorService, IGroupCallback groupCallback, WorkerWrapper... workerWrapper) {
if (groupCallback == null) {
groupCallback = new DefaultGroupCallback();
}
@@ -81,7 +88,7 @@ public class Async {
if (executorService != null) {
executorService.submit(() -> {
try {
boolean success = beginWork(timeout, COMMON_POOL, workerWrapper);
boolean success = beginWork(timeout, executorService, workerWrapper);
if (success) {
finalGroupCallback.success(Arrays.asList(workerWrapper));
} else {