Код: Выделить всё
System.out.println("hello world, CompletableFuturesRightHere");
System.out.println("log1: " + Thread.currentThread().getName());
CompletableFuture cf = CompletableFuture.supplyAsync(() -> {
System.out.println("log-sA: " + Thread.currentThread().getName());
return 40;
}).thenApply( a -> {
System.out.println("log-tA: " + Thread.currentThread().getName());
return a + 40;
});
System.out.println("log3: " + Thread.currentThread().getName());
System.out.println("cf result: " + cf.get());
Код: Выделить всё
hello world, CompletableFuturesRightHere
log1: main
log-sA: ForkJoinPool.commonPool-worker-3
log3: main
log-tA: ForkJoinPool.commonPool-worker-3
cf result: 80
Подробнее здесь: https://stackoverflow.com/questions/757 ... ler-thread
Мобильная версия