private void test() {
CompletableFuture.supplyAsync(new Supplier<String>() {
@Override
public String get() {
System.out.println("开始休眠...");
try {
Thread.sleep(3000);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("休眠结束");
return "线程结果";
}
}).whenComplete(new BiConsumer<String, Throwable>() {
@Override
public void accept(String s, Throwable throwable) {
System.out.println("accept:" + s);
}
});
}