Course contentsShow
← Java
Lesson 2789 of 2,87051. CompletableFutureFree lesson

Default Thread Pool: ForkJoinPool.commonPool()

Discover how supplyAsync and runAsync use the common ForkJoin pool by default for parallel execution.

Default Thread Pool: ForkJoinPool.commonPool()

You'll learn where supplyAsync and runAsync execute their tasks when you don't specify a custom executor.

The Default Execution Engine

When you call supplyAsync() or runAsync() without providing an executor as a second argument, CompletableFuture doesn't create new threads on-the-fly. Instead, it uses a shared, JVM-wide thread pool called ForkJoinPool.commonPool().

This common pool is designed for parallel, work-stealing tasks and is automatically sized based on your system's available processors (typically Runtime.getRuntime().availableProcessors() - 1 threads). Every application running in the same JVM shares this single pool instance.

Why This Matters

Think of ForkJoinPool.commonPool() as a public transportation system: efficient for many small trips, but you wouldn't want a single broken-down bus to delay everyone. When you write:

CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
    return "Hello from the common pool!";
});

This task automatically gets scheduled on the common pool. You didn't manage thread creation, lifecycle, or cleanup—it's all handled transparently.

The Tradeoffs

The common pool provides convenience and efficiency for CPU-bound parallel tasks. However, since it's shared across your entire application, blocking operations (like slow I/O or lengthy database calls) can starve other tasks waiting in the same pool. For specialized workloads, you'll want to provide your own executor—but the common pool remains the sensible default for most quick, non-blocking async operations.

Key Takeaway: supplyAsync() and runAsync() use ForkJoinPool.commonPool() by default—a shared, automatically-sized thread pool optimized for parallel task execution across your entire JVM.