
1. Overview
In this article, we will understand the differences between CompletableFuture vs Future in Java. To learn more about the CompletableFuture, refer to these articles.
2. Java CompletableFuture vs Future
A Future is an interface introduced in Java 5. A CompletableFuture
introduced later in Java 8 implements the Future interface. So CompletableFuture
contains all the functionalities provided by the Future interface.
Additionally, the CompletableFuture
allows you to chain tasks together. Using the CompletableFutures
, we can process the result of the task without actually blocking a thread to wait for the result.
2.1. Java Future interface

The Future is basically a placeholder to hold the result of a task that is not completed yet.
The ExecutorService
executes a task and updates the result in the Future.
The ExecutorService provides submit method which takes a value-returning task (Runnable or Callable) for execution and returns a Future representing the pending results of the task.
Once the task completes, the Future will contain the result.
In the following code, the main thread submits a Callable
task that returns an Integer value as the result to the ExecutorService
. The ExecutorService executes the Callable and updates the result in the future instance upon completion.
public static void main(String[] args) { ExecutorService exec = Executors.newSingleThreadExecutor(); Future<Integer> future = exec.submit(new Callable<Integer>() { @Override public Integer call() throws Exception { System.out.println("Performing mathematical computation.."); return 25; } }); }
The submitter (main thread) of the task can use the Future object to get the result by using the get()
method. Note that this get()
is a blocking call that blocks the main thread and waits for the result.
try { System.out.println(f.get()); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); }
You can also check whether the task is completed by using the isDone()
method.
2.2. Java CompletableFuture
A CompletableFuture
introduced later in Java 8 implements the Future interface. So CompletableFuture
contains all the functionalities provided by the Future interface.
Besides the Future functionalities, the CompletableFuture
allows us to chain the tasks together. Using the CompletableFutures
, we can process the result of the task without actually blocking a thread to wait for the result.
Along with asynchronous programming, the CompletableFuture
handles computation heavy MapReduce (parallel processing by splitting big data sets into smaller chunks) tasks, without worrying much about application performance.
For example, the following CompletableFuture chain multiple tasks together by using the callback methods like thenApply. After CompletableFuture code execution completes (supplyAsync
), it passes the value 5 to the downstream thenApply call where we calculate square of it. Again, passes the square number to the next downstream method and so on.
In Future, we had to block and wait for the thread to get the result. However, we are not blocking the thread here. Once the CompletableFuture completes, the callback methods such as thenApply are invoked for processing the result.
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(() -> { System.out.println("Performing mathematical computation.. 5 "); return 5; }).thenApply(number -> { System.out.println("Result of completable future: " + number); return number * number; }).thenApply(square -> { System.out.println("Result of completable future: " + square); return square*2; }).whenComplete((doubleNumber, throwable) -> { System.out.println("Result of completable future: " + doubleNumber); });
If you execute the above CompletableFuture
, then it prints the following statements in the console. As you see, it passes the result of each task to the next downstream call for further processing.
Performing mathematical computation.. 5 Result of completable future: 5 Result of completable future: 25 Result of completable future: 50
3. Conclusion
To sum up, we have learned the differences between the Future and CompletableFuture in Java. You can get the samples discussed in this article from our GitHub repository.