import java.util.concurrent.CompletableFuture;
import java.util.stream.LongStream;

public class KolamBersama {
    public static void main(String[] args) {
        // CompletableFuture tanpa executor kustom berjalan di
        // ForkJoinPool.commonPool() -- pool bersama seluruh JVM.
        CompletableFuture<String> sapaan = CompletableFuture.supplyAsync(
                () -> "halo dari completablefuture");

        // Parallel stream memakai pool yang sama persis.
        long jumlah = LongStream.rangeClosed(1, 1_000_000)
                .parallel()
                .map(n -> n * n)
                .sum();

        String hasilSapaan = sapaan.join();
        System.out.println("hasil stream paralel     : " + jumlah);
        System.out.println("hasil completablefuture  : " + hasilSapaan);
        System.out.println("kedua jalur tuntas       : " + sapaan.isDone());
    }
}
