为什么在父阶段完成之后,那么notAcceptAsync()并不总是执行?

时间:2018-12-29 02:19:44

标签: java asynchronous executorservice threadpoolexecutor completable-future

我刚刚开始学习使用CompletableFuture。我想知道为什么下面的代码有些奇怪:

public static void main(String[] args) {

    int coreCount = Runtime.getRuntime().availableProcessors();
    ExecutorService service = Executors.newFixedThreadPool(coreCount);

    CompletableFuture.supplyAsync(getStringSupplier(),service)
                     .thenAcceptAsync(getStringConsumer(),service);

    System.out.println(" running main thread");

    service.shutdown();
}

在以上代码中,有时未执行getStringConsumer()方法。有人可以在这里解释我在做什么错吗?

0 个答案:

没有答案