skip to content
everything.concurrency

concurrency

threads, races, locks, the memory model, executors and virtual threads.

  1. 01threadsstarting threads, their lifecycle, and the six states.
  2. 02race conditionstwo threads, one counter++, and a lost update. interleave them yourself.
  3. 03synchronized and monitorsevery object has a lock. entry sets, reentrancy, and what it guards.
  4. 04wait and notifyguarded blocks, spurious wakeups, and why you should use something else.
  5. 05the java memory modelhappens-before, volatile, reordering, and safe publication.
  6. 06atomics and CAScompare-and-swap loops, AtomicInteger, LongAdder, and ABA.
  7. 07locks and AQSReentrantLock, ReadWriteLock, StampedLock, and the queue under all of them.
  8. 08executors and thread poolscore size, max size, the queue, and rejection. play with a pool.
  9. 09CompletableFutureasync pipelines: thenApply, thenCompose, allOf, and error handling.
  10. 10fork/join and work stealingsplit work recursively, idle threads steal from busy ones.
  11. 11concurrent collectionsConcurrentHashMap, CopyOnWriteArrayList, BlockingQueue.
  12. 12synchronizersCountDownLatch, CyclicBarrier, Semaphore, Phaser.
  13. 13deadlocks and livenessdeadlock, livelock, starvation. the dining philosophers, live.
  14. 14virtual threadsjava 21+millions of threads, mounted on a few carriers.
  15. 15structured concurrency and scoped valuesjava 25+task trees that cancel together, and ThreadLocal's replacement.
  16. 16testing concurrent codewhy your test passed 1000 times and failed in prod. jcstress.