我刚刚开始学习使用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()
方法。有人可以在这里解释我在做什么错吗?