⏱️ Section 19 · 28 questions

CompletableFuture and Asynchrony

28 interview questions and answers in the CompletableFuture and Asynchrony section.

Questions in this section

  1. What is CompletableFuture and How Does It Differ from Future
  2. What Are the Main Advantages of CompletableFuture Over Future
  3. How to Create a CompletableFuture That is Already Completed with Result
  4. What is the Difference Between thenApply() and thenCompose()
  5. What Do thenAccept() and thenRun() Methods Do
  6. How to Handle Exceptions in CompletableFuture Chain
  7. What is the Difference Between handle(), exceptionally() and whenComplete()
  8. How to Combine Results of Multiple CompletableFutures
  9. What Does allOf() Method Do and When to Use It
  10. What does anyOf() method do and when is it useful
  11. What is the difference between thenApply() and thenApplyAsync()
  12. What thread pool is used by default for async methods
  13. How to specify your own Executor for CompletableFuture
  14. What is blocking code and how to distinguish it from non-blocking
  15. Why is it important to avoid blocking operations in CompletableFuture
  16. How to properly execute multiple parallel requests to microservices
  17. What does supplyAsync() method do and when to use it
  18. How to cancel CompletableFuture execution
  19. What happens if an exception occurs in CompletableFuture chain
  20. Can you reuse a single CompletableFuture in multiple chains
  21. How to implement timeout for CompletableFuture
  22. What does orTimeout() method do in Java 9+
  23. What is the difference between thenCombine() and thenCompose()
  24. How to test code with CompletableFuture
  25. When is it better to use CompletableFuture vs reactive programming
  26. What does join() method do and how does it differ from get()
  27. Can you manually complete a CompletableFuture with a result
  28. How to implement retry logic with CompletableFuture

Study navigator

28 essential questions and deep-dive architectural analyses for Junior 🟢, Middle 🟡, and Senior 🔴 Java Asynchronous, Concurrent, and High-Throughput Engineers.


📋 Table of Contents

# Question Difficulty
01 What is CompletableFuture and How Does It Differ from Future ⭐
02 What Are the Main Advantages of CompletableFuture Over Future ⭐
03 How to Create a CompletableFuture That is Already Completed with Result ⭐
04 What is the Difference Between thenApply() and thenCompose() ⭐⭐
05 What Do thenAccept() and thenRun() Methods Do ⭐
06 How to Handle Exceptions in CompletableFuture Chain ⭐⭐
07 What is the Difference Between handle(), exceptionally() and whenComplete() ⭐⭐
08 How to Combine Results of Multiple CompletableFutures ⭐⭐
09 What Does allOf() Method Do and When to Use It ⭐⭐
10 What Does anyOf() Method Do and When is It Useful ⭐⭐
11 What is the Difference Between thenApply() and thenApplyAsync() ⭐⭐
12 What Thread Pool is Used by Default for Async Methods ⭐⭐
13 How to Specify Your Own Executor for CompletableFuture ⭐⭐
14 What is Blocking Code and How to Distinguish It from Non-Blocking ⭐
15 Why is It Important to Avoid Blocking Operations in CompletableFuture ⭐⭐
16 How to Properly Execute Multiple Parallel Requests to Microservices ⭐⭐⭐
17 What Does supplyAsync() Method Do and When to Use It ⭐
18 How to Cancel CompletableFuture Execution ⭐⭐
19 What Happens If an Exception Occurs in CompletableFuture Chain ⭐⭐
20 Can You Reuse a Single CompletableFuture in Multiple Chains ⭐⭐
21 How to Implement Timeout for CompletableFuture ⭐⭐
22 What Does orTimeout() Method Do in Java 9+ ⭐⭐
23 What is the Difference Between thenCombine() and thenCompose() ⭐⭐
24 How to Test Code with CompletableFuture ⭐⭐
25 When is It Better to Use CompletableFuture vs Reactive Programming ⭐⭐⭐
26 What Does join() Method Do and How Does It Differ from get() ⭐
27 Can You Manually Complete a CompletableFuture with a Result ⭐⭐
28 How to Implement Retry Logic with CompletableFuture ⭐⭐⭐

🗺️ Topic Dependency Map

                    ┌──────────────────────────────────────────┐
                    │      ASYNC FOUNDATIONS (01-03, 17, 26-27)│
                    │   01-02. CompletableFuture vs Future     │
                    │   03, 27. Manual & Immediate Completion  │
                    │   17. supplyAsync & runAsync             │
                    │   26. join() vs get() & Exceptions       │
                    └──────────────────┬───────────────────────┘
                                       │
            ┌──────────────────────────┼──────────────────────────┐
            ▼                          ▼                          ▼
    ┌───────────────┐        ┌───────────────┐        ┌────────────────────┐
    │ CHAINING &    │        │ COMBINING &   │        │ EXECUTORS & THREAD │
    │ MONADS (04-05)│        │ FAN-OUT (08-10│        │ POOLS (11-15)      │
    │ 04. Apply/Comp│        │   16, 23)     │        │ 11. Async Variant  │
    │ 05. Accept/Run│        │ 08, 23. Combine│        │ 12. ForkJoinPool   │
    │ 20. DAG Reuse │        │ 09. allOf()   │        │ 13. Custom Pool    │
    └───────┬───────┘        │ 10. anyOf()   │        │ 14-15. Anti-Block  │
            │                │ 16. Svc Scatter│       └────────┬───────────┘
            │                └───────┬───────┘                 │
            │                        │                         │
            └────────────────────────┼─────────────────────────┘
                                     ▼
                    ┌──────────────────────────────────────────┐
                    │  FAULT TOLERANCE, TIMEOUTS & OPS (06-07, │
                    │   18-19, 21-22, 24-25, 28)               │
                    │   06-07, 19. Exception Handling Pipeline │
                    │   18. Cancellation Mechanics             │
                    │   21-22. Timeout & orTimeout (Java 9+)   │
                    │   24. Deterministic Async Unit Testing   │
                    │   25. CF vs Project Reactor & RxJava     │
                    │   28. Asynchronous Exponential Retries   │
                    └──────────────────────────────────────────┘

🟢 Junior Track (Core Concepts & Pipeline Basics)

🟡 Middle Track (Thread Pools, Aggregations & Resilience)

🔴 Senior Track (Microservices Architecture, Non-Blocking Systems & Retries)