mirror of
https://gitee.com/jd-platform-opensource/asyncTool.git
synced 2024-12-31 15:35:34 +08:00
加一个重载方法
This commit is contained in:
parent
1c39d5853e
commit
d6e7777460
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.jd.platform</groupId>
|
||||
<artifactId>asyncTool</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.3.1-SNAPSHOT</version>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -24,15 +24,10 @@ public class Async {
|
||||
new LinkedBlockingQueue<>(),
|
||||
(ThreadFactory) Thread::new);
|
||||
|
||||
/**
|
||||
* 如果想自定义线程池,请传pool。不自定义的话,就走默认的COMMON_POOL
|
||||
*/
|
||||
public static boolean beginWork(long timeout, ThreadPoolExecutor pool, WorkerWrapper... workerWrapper) throws ExecutionException, InterruptedException {
|
||||
if(workerWrapper == null || workerWrapper.length == 0) {
|
||||
public static boolean beginWork(long timeout, ThreadPoolExecutor pool, List<WorkerWrapper> workerWrappers) throws ExecutionException, InterruptedException {
|
||||
if(workerWrappers == null || workerWrappers.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
List<WorkerWrapper> workerWrappers = Arrays.stream(workerWrapper).collect(Collectors.toList());
|
||||
|
||||
CompletableFuture[] futures = new CompletableFuture[workerWrappers.size()];
|
||||
for (int i = 0; i < workerWrappers.size(); i++) {
|
||||
WorkerWrapper wrapper = workerWrappers.get(i);
|
||||
@ -51,6 +46,17 @@ public class Async {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果想自定义线程池,请传pool。不自定义的话,就走默认的COMMON_POOL
|
||||
*/
|
||||
public static boolean beginWork(long timeout, ThreadPoolExecutor pool, WorkerWrapper... workerWrapper) throws ExecutionException, InterruptedException {
|
||||
if(workerWrapper == null || workerWrapper.length == 0) {
|
||||
return false;
|
||||
}
|
||||
List<WorkerWrapper> workerWrappers = Arrays.stream(workerWrapper).collect(Collectors.toList());
|
||||
return beginWork(timeout, pool, workerWrappers);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步阻塞,直到所有都完成,或失败
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user