Phase 05: Concurrency & Multithreading — Where Careers Get Made

Timeline: Months 6-8 (Weeks 21-32) Estimated Effort: 10-15 hrs/week (~130-180 hours total)


Why This Phase Exists

Concurrency is the single technical area where the gap between a mid-level and a senior Java engineer is largest, and it’s the area where an ML background helps you the least. You’re used to reasoning about data flows and gradients, not about “what if two threads see this write in different orders.” This phase closes that gap.

You will finish this phase able to look at a screenful of Java, say “there’s a race condition on line 47 because of how the JMM handles visibility,” and be right. That’s what senior engineers get paid for. That’s also what saves a Zoho monolith from a 2 AM production incident.

This phase also contains the single biggest shift in Java since generics: Project Loom / Virtual Threads (Java 21). If you learn only pre-Loom concurrency, you’ll write code that Was Best Practice In 2019. Learn both. Know when each wins.


What You’ll Cover

#

Topic

File

Focus

1

Threads & Memory Model

01_threads_and_memory_model.md

JMM, volatile, happens-before, atomics, false sharing, double-checked locking

2

Synchronization & Locks

02_synchronization_and_locks.md

synchronized, ReentrantLock, ReadWriteLock, StampedLock, Condition, deadlock avoidance

3

Executors & Thread Pools

03_executors_and_thread_pools.md

ExecutorService, sizing, rejection policies, Future vs CompletableFuture

4

Concurrent Collections

04_concurrent_collections.md

ConcurrentHashMap, CopyOnWriteArrayList, blocking queues, producer-consumer

5

Virtual Threads (Loom)

05_virtual_threads_project_loom.md

M:N scheduling, pinning, ThreadLocal traps, structured concurrency, migration

6

Debugging Concurrency

06_debugging_concurrency.md

Thread dumps, jstack, deadlock reports, jcstress, race reproduction

7

Phase Projects

projects.md

Rate limiter, virtual-thread benchmark, real deadlock post-mortem


How to Work Through This Phase

  1. Weeks 21-22: Files 01-02. This is the theory floor. Do not move on until happens-before and lock semantics feel obvious.

  2. Weeks 23-24: Files 03-04. Build a thread pool by hand once, then never do it again.

  3. Week 25: File 05. Virtual threads. Read the JEPs, run the pinning demo, feel the difference.

  4. Week 26: File 06 + start Project (a) — the rate limiter.

  5. Weeks 27-28: Project (b) — the virtual-thread benchmark. This is the money project.

  6. Weeks 29-30: Project (c) — deadlock post-mortem. Slow, careful, write like a staff engineer would.

  7. Weeks 31-32: Buffer. study questions. Review. Every phase runs long.


Exit Criteria

You’re done when you can honestly answer “yes” to every one of these:

  • You can explain the Java Memory Model in five sentences: what volatile guarantees, what synchronized guarantees, and what “happens-before” means operationally.

  • Given a thread dump, you can identify a deadlock in under two minutes and name the two locks and threads involved.

  • You know why Executors.newFixedThreadPool is dangerous in production and can code the safe alternative from memory.

  • You can size a thread pool for a CPU-bound vs an I/O-bound workload and defend the number.

  • You can explain, unprompted, three ways virtual threads will bite you: synchronized pinning (pre-Java 24), ThreadLocal misuse, and false confidence in CPU-bound scenarios.

  • You know when CompletableFuture is better than virtual threads and vice versa.

  • You’ve completed the rate limiter, the virtual-thread benchmark, and the deadlock post-mortem.

  • You can read a jstack output cold and describe what each thread is doing.


⚠️ What Most People Get Wrong

They read Goetz’s Java Concurrency in Practice front-to-back, feel enlightened, then write code that would horrify Doug Lea. Concurrency is not a reading subject. You have to break things, watch them fail, and reason about why. The Project (c) post-mortem — where you take a deadlocked codebase, reproduce the bug, fix it, and write it up — is worth more than the first four books you’ll read on the topic.

Also: they treat virtual threads as a drop-in speed boost. They aren’t. Netflix has published cases where migrating to virtual threads broke production because of monitor pinning in JDBC drivers and ConcurrentHashMap.computeIfAbsent. Loom is a tool, not a fix.


Prerequisites

Phases 01-04 complete. In particular:

  • You can write Java without an IDE autocompleting your for loops.

  • You’ve written non-trivial code with streams, records, sealed classes.

  • You’ve built at least one project bigger than 500 lines.

If you’re shaky on any of that, go back. Concurrency on a weak foundation is how careers get unmade.


Return to ../README.md · Next: 01_threads_and_memory_model.md