实现异步操作CompletableFuture

多个线程异步操作后统一返回执行结果AtomicReference<RespVo> event = new AtomicReference<>();

AtomicReference<Response> meet = new AtomicReference<>();
AtomicReference<ResVo> meet=new AtomicReference<>();
CompletableFuture<Void> completableFuture = CompletableFuture.allOf(
     CompletableFuture.runAsync(()->{
        event.set(event1);
     }},executorService),
     CompletableFuture.runAsync(()->{       
         meet.set();   
     },executorService)
);
completableFuture.join();  
event.get();
meet.get();

 

posted @ 2023-03-16 09:41  sowler  阅读(18)  评论(0编辑  收藏  举报