当我使用CompletableFuture的默认线程池时,只输出:main线程结束了,为什么不输出:最终结果为=
public class Test {
public static void main(String[] args) throws ExecutionException, InterruptedException {
CompletableFuture.supplyAsync(() -> {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "hello";
}).whenComplete((v, e) -> {
if (e == null) {
System.out.println("最终结果为=" + v);
}
}).exceptionally(e -> {
System.out.println("出现异常=" + e);
return null;
});
System.out.println("main线程结束了");
}
}