I am trying to implement a thread pool using ExecutorService and CompletableFuture in java. Here I have passed the fixed-size pool to completable future tasks. if I don't pass the executor service here in completable future tasks it will use Fork/Join common pool internally as I read. Now my question is should I pass executor service here externally or not and let it use Fork/Join common pool internally? which is better in which case?
ExecutorService es = Executors.newFixedThreadPool(4);
List<CompletableFuture<?>> futures = new ArrayList<>();
for(item i: item[]){
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> MyClass.service(i), es);
futures.add(future);
}
CompletableFuture.allOf(futures.toArray(new CompletableFuture[]{})).join();