Module 05
Multithreading & Concurrency
From your first thread to the Java Memory Model, locks, executors, CompletableFuture and virtual threads, with many scenario questions.
By the end of this module you can
- Reason about visibility, ordering and happens-before
- Choose between synchronized, locks, atomics and concurrent collections
- Diagnose deadlocks and tune thread pools
Thread basics
Processes vs threads, creating threads, lifecycle and interrupts.
- Beginner's guide to Java multithreadingFree
- Processes vs threadsFreeSoon
- Creating threads: Thread, Runnable and CallableFreeSoon
- Thread lifecycle and statesFreeSoon
- Daemon threads and prioritiesPremiumSoon
- Interrupts and cancellationPremiumSoon
- Thread basics: interview questions & scenariosPremiumSoon
Synchronization
Race conditions, monitors, wait/notify and producer–consumer.
- Race conditionsFreeSoon
- synchronized and monitorsFreeSoon
- ReentrancyPremiumSoon
- wait(), notify() and notifyAll()PremiumSoon
- Why wait() and notify() need synchronizedFree
- The producer–consumer problemPremiumSoon
- Synchronization: interview questions & scenariosPremiumSoon
Java Memory Model
Visibility, reordering, happens-before, volatile and safe publication.
- Visibility and reorderingPremiumSoon
- Happens-beforePremiumSoon
- volatilePremiumSoon
- Safe publication and double-checked lockingPremiumSoon
- final field semanticsPremiumSoon
- Java Memory Model: interview questions & scenariosPremiumSoon
Atomics & CAS
Lock-free building blocks.
- Atomic classesPremiumSoon
- Compare-and-swap and the ABA problemPremiumSoon
- LongAdder and striped countersPremiumSoon
- Atomics & CAS: interview questions & scenariosPremiumSoon
Locks
Explicit locks and when to use them.
- ReentrantLock and ConditionPremiumSoon
- ReadWriteLockPremiumSoon
- StampedLockPremiumSoon
- Lock fairnessPremiumSoon
- Locks: interview questions & scenariosPremiumSoon
Liveness
Deadlock, livelock, starvation and thread dumps.
- Deadlock detection and preventionPremiumSoon
- Livelock and starvationPremiumSoon
- Reading thread dumpsPremiumSoon
- Liveness: interview questions & scenariosPremiumSoon
Executors & thread pools
ExecutorService, ThreadPoolExecutor internals and sizing.
- ExecutorService and thread poolsPremiumSoon
- ThreadPoolExecutor internalsPremiumSoon
- Rejection policiesPremiumSoon
- Scheduled executorsPremiumSoon
- Sizing thread poolsPremiumSoon
- Executors & thread pools: interview questions & scenariosPremiumSoon
Coordination utilities
Latches, barriers, semaphores and phasers.
- CountDownLatchPremiumSoon
- CyclicBarrierPremiumSoon
- SemaphorePremiumSoon
- PhaserPremiumSoon
- Coordination utilities: interview questions & scenariosPremiumSoon
Concurrent collections
ConcurrentHashMap internals, copy-on-write and blocking queues.
- How ConcurrentHashMap worksPremiumSoon
- CopyOnWriteArrayListPremiumSoon
- BlockingQueue implementationsPremiumSoon
- Concurrent collections: interview questions & scenariosPremiumSoon
Async programming
Futures, CompletableFuture and Fork/Join.
- Future and CallablePremiumSoon
- How CompletableFuture worksPremiumSoon
- Fork/Join and work stealingPremiumSoon
- Async programming: interview questions & scenariosPremiumSoon
ThreadLocal
Per-thread state and its pitfalls.
- ThreadLocal and InheritableThreadLocalPremiumSoon
- ThreadLocal memory leaksPremiumSoon
- ThreadLocal: interview questions & scenariosPremiumSoon
Modern concurrency
Virtual threads, structured concurrency and scoped values.
- Virtual threadsPremiumSoon
- Structured concurrency and scoped valuesPremiumSoon
- Modern concurrency: interview questions & scenariosPremiumSoon
Concurrency coding problems
Classic problems you may be asked to code live.
- Concurrency coding problemsPremiumSoon
- Concurrency coding problems: interview questions & scenariosPremiumSoon
Module interview question bank
Finish the module
Module interview question bankEvery interview question worth practising for Multithreading & Concurrency, grouped by topic, with model answers, how to say them and what-if follow-ups.