Skip to content
Ameen Abozaid
Planned lessonMID-006-L01

Futures vs CompletableFuture

  • Lesson 1 of 6
  • Mid-level
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

see why Future is limiting and what CompletableFuture adds.

Planned topics

  • Future.get() blocks; there is no way to say "when done, do X".
  • CompletableFuture<T> is a future you can chain, combine, and complete manually.
  • supplyAsync runs a value-producing task; runAsync a no-result task.
  • Each stage returns a new future; build a pipeline instead of blocking.
  • Block only at the edge of the system, if at all.
Draft outline details

Demonstration

java
CompletableFuture<Product> p = CompletableFuture.supplyAsync(() -> productClient.get(id), ioPool);

Check your understanding

What can a CompletableFuture do that Future cannot?

Show answer

Chain callbacks and combine results without blocking.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.