public static void main(String[] args) throws ExecutionException, InterruptedException { // 异步调用,没有返回值 CompletableFuture<Void> completableFuture1 = CompletableFuture.runAsync(() -> { System.out.println(Thread.currentThread().getName()+"completableFuture1"); }); //异步调用有返回值 CompletableFuture<Integer> completableFuture2=CompletableFuture.supplyAsync(()->{ System.out.println(Thread.currentThread().getName()+"completableFuture2"); return 12306; }); System.out.println(completableFuture2.get()); CompletableFuture<Integer> completableFuture3=CompletableFuture.supplyAsync(()->{ System.out.println(Thread.currentThread().getName()+"completableFuture3"); int a=1/0; return 12306; }); Integer integer = completableFuture3.whenComplete((num, error) -> { System.out.println("num:" + num); System.out.println("error:" + error); }).get(); System.out.println(integer); }