Async Execution Models: Common vs Custom Executors
You'll learn when CompletableFuture uses the default thread pool and when you should provide your own Executor.
The Default: ForkJoinPool.commonPool()
When you call async methods on CompletableFuture without specifying an Executor (like supplyAsync(supplier)), Java uses the ForkJoinPool.commonPool() by default. This is a shared, application-wide thread pool designed for CPU-intensive, parallelizable tasks.
Think of it like using the hotel's shared business center — convenient and zero setup, but everyone's fighting for the same resources.
When the Common Pool Works Fine
The common pool is perfectly adequate for:
- CPU-bound tasks that don't block
- Short-lived computations that complete quickly
- Applications with minimal async workload
// Uses ForkJoinPool.commonPool() implicitly
CompletableFuture.supplyAsync(() -> expensiveComputation());
When You Need a Custom Executor
Provide your own Executor when:
- Blocking I/O operations (file/network reads): The common pool's threads would sit idle, starving other tasks
- Long-running tasks: You need dedicated threads that won't monopolize the common pool
- Different thread priorities or configurations: Daemon status, thread names for debugging, custom thread factories
- Isolation requirements: Separate pools for different subsystems prevent one component from blocking another
ExecutorService customPool = Executors.newFixedThreadPool(10);
// Explicitly use your custom pool
CompletableFuture.supplyAsync(() -> readFromDatabase(), customPool);
The async method variants ending in "Async" (like thenApplyAsync) accept an optional Executor parameter.
Key Takeaway:
Use the default common pool for quick, CPU-bound tasks; provide a custom Executor for blocking I/O, long-running operations, or when you need thread pool isolation and control.