Differences between CompletableFuture and Future in Java 9?

CompletableFuture<T> class implements Future<T> interface in Java. CompletableFuture can be used as a Future that has explicitly completed. The Future interface doesn’t provide a lot of features, we need to get the result of asynchronous computation using the get() method, which is blocked, so there is no scope to run multiple dependent tasks in a non-blocking fashion whereas CompleteFuture class can provide the functionality to chain multiple dependent tasks that run asynchronously, so we can create a chain of tasks where the next task is triggered when the result of the current task is available.


public class CompletableFuture<T> extends Object implements Future<T>, CompletionStage<T>


import java.util.function.Supplier;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class CompletableFutureTest {
   public static void main(String args[]) throws ExecutionException, InterruptedException {
      Calculator calc = new Calculator(4, 7);
      CompletableFuture<Integer> future = CompletableFuture.supplyAsync(calc);
      future.thenAccept(result -> {
      System.out.println("CompletableFutureTest End.... ");

// Calculator class
class Calculator implements Supplier<Integer> {
   private int x, y;
   public Calculator(int x, int y) {
      this.x = x;
      this.y = y;
   public Integer get() {
      try {
      } catch(InterruptedException e) {
      return x + y;


CompletableFutureTest End....

Updated on: 01-May-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started