import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public static void main(String[] args) throws ExecutionException, InterruptedException {
CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(()->{
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
System.out.println(Thread.currentThread().getName() + "runAsync");
CompletableFuture<Integer> future = CompletableFuture.supplyAsync(
System.out.println(Thread.currentThread().getName() + "supplyAsync,toInt");
future.whenComplete((t, u)->{
System.out.println("t=" + t);
System.out.println("u=" + u);
}).exceptionally((e)->{e.printStackTrace();
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。