mirror of
https://gitee.com/jd-platform-opensource/asyncTool.git
synced 2024-12-31 15:35:34 +08:00
commit
f323f37ded
@ -15,6 +15,9 @@ import java.util.stream.Collectors;
|
|||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
public class Async {
|
public class Async {
|
||||||
|
/**
|
||||||
|
* 默认线程池
|
||||||
|
*/
|
||||||
private static final ThreadPoolExecutor COMMON_POOL =
|
private static final ThreadPoolExecutor COMMON_POOL =
|
||||||
new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors() * 2, 1024,
|
new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors() * 2, 1024,
|
||||||
15L, TimeUnit.SECONDS,
|
15L, TimeUnit.SECONDS,
|
||||||
@ -72,10 +75,14 @@ public class Async {
|
|||||||
return beginWork(timeout, COMMON_POOL, workerWrapper);
|
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) {
|
if (groupCallback == null) {
|
||||||
groupCallback = new DefaultGroupCallback();
|
groupCallback = new DefaultGroupCallback();
|
||||||
}
|
}
|
||||||
@ -83,7 +90,7 @@ public class Async {
|
|||||||
if (executorService != null) {
|
if (executorService != null) {
|
||||||
executorService.submit(() -> {
|
executorService.submit(() -> {
|
||||||
try {
|
try {
|
||||||
boolean success = beginWork(timeout, COMMON_POOL, workerWrapper);
|
boolean success = beginWork(timeout, executorService, workerWrapper);
|
||||||
if (success) {
|
if (success) {
|
||||||
finalGroupCallback.success(Arrays.asList(workerWrapper));
|
finalGroupCallback.success(Arrays.asList(workerWrapper));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user