- public CompletableFuture<Void> thenAccept(Consumer<? super T> action)
- public CompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action)
- public CompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action, Executor executor)
留意这几个办法都邑返回CompletableFuture,当Action履行完毕后它的结不雅返回原始的CompletableFuture的计算结不雅或者返回异常。
- public class Main {
- private static Random rand = new Random();
- private static long t = System.currentTimeMillis();
- static int getMoreData() {
- System.out.println("begin to start compute");
- try {
- Thread.sleep(10000);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- System.out.println("end to start compute. passed " + (System.currentTimeMillis() - t)/1000 + " seconds");
- return rand.nextInt(1000);
- }
- public static void main(String[] args) throws Exception {
- CompletableFuture<Integer> future = CompletableFuture.supplyAsync(Main::getMoreData);
- Future<Integer> f = future.whenComplete((v, e) -> {
推荐阅读
【限时免费】岁尾最强一次云计算大年夜会,看传统、社区、互联网企业若何碰撞?【编辑推荐】2017 Android和iOS几回再三被曝Bug,它们都怎么了?谷歌苹不雅竟齐翻车!谈谈安卓8/iOS11那些BugiOS消息转发>>>详细阅读
地址:http://www.17bianji.com/lsqh/40058.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示