异步调用就像是ajax一样可以不用等待直接执行其他的方法
package net.yscxy.future;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
/**
* @Author WangFuKun
* @create 2020/12/2 9:20
*/
/*
* 异步调用,类似ajax
* */
public class Demo01 {
public static void main(String[] args) throws ExecutionException, InterruptedException {
CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(() -> {
System.out.println(Thread.currentThread().getName() + "supplyAsync=>Integer");
return 1024;
});
System.out.println(completableFuture.whenComplete((u, t) -> {
System.out.println("u->" + u);
System.out.println("t->" + t);
}).exceptionally((e) -> {
System.out.println( e.getMessage());
return 233;
}).get());
}
}