↓ Skip to main content

Java Concurrency Roadmap

·278 words·2 mins

Threads in one Java process share the heap, and every concurrency problem comes from that. Two threads touching the same mutable state need two guarantees: mutual exclusion (only one changes it at a time) and visibility (the other thread sees the change). synchronized and locks give you both. volatile gives only visibility. On top of that, java.util.concurrent adds coordination tools, thread pools, and collections that do the locking for you. The most common production bugs are compound actions that look atomic but aren’t, and badly sized thread pools.

This page is the map. Each line links to a short note with the details.

Foundations
#

  1. Fundamentals: process vs thread, thread states, start() vs run(), context switching, daemon threads, priorities.
  2. Synchronization basics: shared state and critical sections, race conditions, synchronized and monitors, volatile, what is and isn’t atomic.
  3. Thread communication: wait/notifyAll, join/sleep, interrupts and cancellation.
  4. Concurrency problems: deadlock, livelock, starvation, priority inversion, what “thread-safe” means.
  5. Java Memory Model: visibility, happens-before, instruction reordering, CPU caches and barriers.

Tools from java.util.concurrent
#

  1. Locks: ReentrantLock, ReadWriteLock, StampedLock, Condition, fair vs unfair.
  2. Synchronizers: Semaphore, CountDownLatch, CyclicBarrier, Phaser, Exchanger.
  3. Atomics and CAS: atomic variables, compare-and-swap, the ABA problem, lock-free vs wait-free.
  4. Executors and thread pools: ThreadPoolExecutor settings, rejection policies, scheduling, Future.
  5. Async and Fork/Join: CompletableFuture, work stealing, parallel streams.
  6. Concurrent collections: ConcurrentHashMap, CopyOnWriteArrayList, BlockingQueue variants. See also which collection to use.

Beyond the basics
#

  1. Advanced topics: ThreadLocal, structured concurrency, immutability, the actor model. Virtual threads have their own note: WebSockets, threading and virtual threads. Reactive is covered in WebFlux and reactive programming.
  2. Classic problems: producer-consumer, dining philosophers, readers-writers, sleeping barber, odd/even printing.
  3. Debugging and performance: thread dumps, deadlock detection, lock contention, Amdahl’s law.
Amar Singh
Author
Amar Singh
I build stuff

Related