Skip to content

Path 4 of 4

Executors, Async and Virtual Threads

Thread pools and what happens when they fill, CompletableFuture, concurrent collections, ForkJoinPool, and virtual threads in Java 21: what they change and what they cannot.

0 / 5 lessons completed · about 140 min in total

After this path you can

Outcomes

  • Size a pool and its queue, and choose a rejection policy
  • Compose asynchronous work without starving a pool
  • Decide where virtual threads help and where they do not
  • Diagnose thread starvation from a thread dump

Lessons

  1. 1Executors, thread pools and rejectionHow ThreadPoolExecutor decides between a thread, the queue and rejection, why an unbounded queue hides overload, and how to find a starved pool in a thread dump.Intermediate28 min
  2. 2CompletableFuture and asynchronous executionWhich thread runs each stage, how to compose calls without blocking, how errors and timeouts travel, and why join() inside a pool task can stop the pool for good.Intermediate30 min
  3. 3Concurrent collections and ConcurrentHashMapHow ConcurrentHashMap lets many threads work at once, which of its operations are atomic, why check-then-act on it is still a race, and what the other concurrent collections are for.Intermediate28 min
  4. 4ForkJoinPool and work stealingHow ForkJoinPool runs split-up work on per-worker deques, what the common pool is and who shares it, and how one blocking parallel stream starves unrelated code.Advanced26 min
  5. 5Virtual threads in Java 21What a virtual thread is, how carriers mount and unmount it, why it helps blocking I/O only, what pinning is in JDK 21, and why the bottleneck moves to the downstream limit.Advanced28 min

Simulations and labs for this path

A simulation in the browser, then the same failure on a real JVM.

  1. Simulation 1Thread pool exhaustion: four threads, five times the load
  2. Simulation 6Lock contention: eight threads, the throughput of one
  3. Simulation 7Virtual threads: where they help and where they cannot
  4. Simulation 8CompletableFuture starvation: a pool waiting for itself