CompletableFutureFlow { static CompletableFuture<Integer> flowWithId(int id, ExecutorService pool) { return firstOperation(id, pool) .thenCompose(__ -> secondOperation(id, pool)) .thenCompose(__ -> thirdOperation(id, pool)); }    }
@Test public void testFlowWithCommonForkJoinPool() throws Exception { pool = ForkJoinPool.commonPool(); List<CompletableFuture<Integer>> futures = new ArrayList<>(); for (int i = 0; i < 20; i++) { futures.add( CompletableFutureFlow.flowWithId(i, pool)); } futures.forEach(CompletableFutureFlow::getFuture); }
@Test public void testFlowWithFixedThreadPool() throws Exception { pool = Executors.newFixedThreadPool(POOL_SIZE); List<CompletableFuture<Integer>> futures = new ArrayList<>(); for (int i = 0; i < 20; i++) { futures.add( CompletableFutureFlow.flowWithId(i, pool)); } futures.forEach(CompletableFutureFlow::getFuture); }
@Test public void testFlowWithCustomForkJoinPool() throws Exception { pool = new ForkJoinPool(POOL_SIZE); List<CompletableFuture<Integer>> futures = new ArrayList<>(); for (int i = 0; i < 20; i++) { futures.add( CompletableFutureFlow.flowWithId(i, pool)); } futures.forEach(CompletableFutureFlow::getFuture); }