Skip to main content

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

Notes are being added. Planned topics:

TopicDescription
Threads & LifecycleThread, Runnable, lifecycle states, start/join/interrupt.
Synchronizationsynchronized, intrinsic locks, volatile, happens-before.
Wait / NotifyObject monitor-based coordination; spurious wakeup rule.
java.util.concurrentExecutorService, Future, CompletableFuture, CountDownLatch.
LocksReentrantLock, ReadWriteLock, StampedLock — explicit locking.
Atomic VariablesAtomicInteger, AtomicReference, LongAdder — lock-free CAS operations.
Thread Safety PatternsImmutability, ThreadLocal, confinement.
Virtual Threads (Java 21+)Project Loom — Thread.ofVirtual(), pinning, structured concurrency.

Learning Path

  1. Threads & Lifecycle — understand the NEW → RUNNABLE → BLOCKED/WAITING → TERMINATED state machine.
  2. Synchronizationsynchronized and volatile are the most tested fundamentals.
  3. java.util.concurrentExecutorService replaces manual thread management; CompletableFuture handles async pipelines.
  4. Locks & Atomic Variables — needed for high-performance scenarios requiring more control than synchronized.
  5. Virtual Threads — finish here; they require a solid understanding of platform threads to appreciate the difference.
  • Collections FrameworkConcurrentHashMap, 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.