import java.util.concurrent.CompletableFuture;
@Qualifier("taskExecutor")
@Resource
private ThreadPoolTaskExecutor taskExecutor;
List<CompletableFuture> futures = new ArrayList<>();
futures.add(CompletableFuture.runAsync(() -> {
this.多线程方法1
}, taskExecutor).whenComplete((re, ex)->{
if(null != ex) {
log.error("。。。。异常", ex);
}
}));
futures.add(CompletableFuture.runAsync(() -> {
this.多线程方法2
}, taskExecutor).whenComplete((re, ex)->{
if(null != ex) {
log.error("。。。。异常", ex);
}
}));
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
java 多线程同步结束
最新推荐文章于 2024-08-19 16:01:20 发布