加一个重载方法

This commit is contained in:
wuweifeng10 2020-04-20 11:51:03 +08:00
parent 1c39d5853e
commit d6e7777460
2 changed files with 14 additions and 8 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.jd.platform</groupId> <groupId>com.jd.platform</groupId>
<artifactId>asyncTool</artifactId> <artifactId>asyncTool</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.3.1-SNAPSHOT</version>
<build> <build>
<plugins> <plugins>

View File

@ -24,15 +24,10 @@ public class Async {
new LinkedBlockingQueue<>(), new LinkedBlockingQueue<>(),
(ThreadFactory) Thread::new); (ThreadFactory) Thread::new);
/** public static boolean beginWork(long timeout, ThreadPoolExecutor pool, List<WorkerWrapper> workerWrappers) throws ExecutionException, InterruptedException {
* 如果想自定义线程池请传pool不自定义的话就走默认的COMMON_POOL if(workerWrappers == null || workerWrappers.size() == 0) {
*/
public static boolean beginWork(long timeout, ThreadPoolExecutor pool, WorkerWrapper... workerWrapper) throws ExecutionException, InterruptedException {
if(workerWrapper == null || workerWrapper.length == 0) {
return false; return false;
} }
List<WorkerWrapper> workerWrappers = Arrays.stream(workerWrapper).collect(Collectors.toList());
CompletableFuture[] futures = new CompletableFuture[workerWrappers.size()]; CompletableFuture[] futures = new CompletableFuture[workerWrappers.size()];
for (int i = 0; i < workerWrappers.size(); i++) { for (int i = 0; i < workerWrappers.size(); i++) {
WorkerWrapper wrapper = workerWrappers.get(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);
}
/** /**
* 同步阻塞,直到所有都完成,或失败 * 同步阻塞,直到所有都完成,或失败
*/ */