Multithreading & Concurrency
Concurrency is one of the hardest topics in Java — and one of the most heavily interviewed. Getting it wrong leads to race conditions and data corruption that are nearly impossible to reproduce. This domain covers threads from the basics through the state-of-the-art: Java 21's virtual threads (Project Loom), which change the scalability calculus for thread-per-request server applications.
What You'll Find Here
| Topic | Description |
|---|---|
| Threads & Lifecycle | Thread, Runnable, lifecycle states, start/join/interrupt, daemon threads. |
| Synchronization | synchronized, intrinsic locks, volatile, happens-before, double-checked locking. |
| Wait / Notify | Object monitor-based coordination; spurious wakeup rule; notify vs notifyAll. |
| java.util.concurrent | ExecutorService, Future, CompletableFuture, CountDownLatch, Semaphore. |
| Locks | ReentrantLock, ReadWriteLock, StampedLock — explicit locking with fine control. |
| Atomic Variables | AtomicInteger, AtomicReference, LongAdder — lock-free CAS operations. |
| Thread Safety Patterns | Immutability, ThreadLocal, confinement, safe publication. |
| Virtual Threads (Java 21+) | Project Loom — Thread.ofVirtual(), pinning, structured concurrency. |
Learning Path
- Threads & Lifecycle — understand the NEW → RUNNABLE → BLOCKED/WAITING → TERMINATED state machine.
- Synchronization —
synchronizedandvolatileare the most tested fundamentals. - Wait / Notify — the old-school coordination mechanism; needed to understand what
BlockingQueuereplaces. - java.util.concurrent —
ExecutorServicereplaces manual thread management;CompletableFuturehandles async pipelines. - Locks — explicit locking for timed, interruptible, or multi-condition scenarios.
- Atomic Variables — lock-free CAS for high-throughput counters and flags.
- Thread Safety Patterns — design-level strategies that eliminate the need for locks entirely.
- Virtual Threads (Java 21+) — finish here; requires a solid understanding of platform threads to appreciate the difference.
Related Domains
- Collections Framework —
ConcurrentHashMap,BlockingQueue, and thread-safe collection wrappers. - JVM Internals — the JVM memory model and GC pauses affect concurrent program behavior.
- Spring Boot —
@Async, virtual thread executor configuration, and servlet threading model.