Skip to content
Veltoryx Technologies
ProLesson 9.8Advanced3 min readUpdated 30 October 2026

Callable, Future and CompletableFuture

Get results back from background tasks with Callable and Future, then compose asynchronous work fluently with CompletableFuture.

A Runnable returns nothing. Usually you want a result back: a price from one service, stock from another. Java gives you Callable and Future, and the far more powerful CompletableFuture.

01Callable and Future

FutureDemo.java
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class FutureDemo {
    public static void main(String[] args) throws Exception {
        try (ExecutorService pool = Executors.newFixedThreadPool(2)) {
            Callable<Integer> fetchStock = () -> {
                Thread.sleep(100);          // pretend: call the inventory service
                return 42;
            };
            Future<Integer> future = pool.submit(fetchStock);   // starts in the background

            System.out.println("Doing other work...");
            int stock = future.get();                            // blocks until the result is ready
            System.out.println("Stock: " + stock);
            System.out.println("Done? " + future.isDone());
        }
    }
}
Expected output
Doing other work...
Stock: 42
Done? true

A Future is a promise of a result later. get() waits for it. If the task threw an exception, get() throws ExecutionException with the original as its cause.

The limits of Future: get() blocks, there's no clean way to chain "when done, do X", and combining several futures is clumsy.

Loading the rest of the lesson…