让同步执行结果有个返回值

This commit is contained in:
wuweifeng10 2019-12-27 17:02:21 +08:00
parent b7c36196f4
commit 73db76404c

View File

@ -33,7 +33,7 @@ public class Async {
CompletableFuture[] futures = new CompletableFuture[workerWrappers.size()];
for (int i = 0; i < workerWrappers.size(); i++) {
WorkerWrapper wrapper = workerWrappers.get(i);
futures[i] = CompletableFuture.runAsync(() -> wrapper.work(COMMON_POOL, timeout), COMMON_POOL);
futures[i] = CompletableFuture.runAsync(() -> wrapper.work(COMMON_POOL, timeout), pool);
}
try {
CompletableFuture.allOf(futures).get(timeout, TimeUnit.MILLISECONDS);