Course contents

Module 05

Multithreading & Concurrency

From your first thread to the Java Memory Model, locks, executors, CompletableFuture and virtual threads, with many scenario questions.

Premium7 free lessons13 topics61 lessons & question sets2 ready

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.

  1. Beginner's guide to Java multithreadingFree guide · already liveFree
  2. Processes vs threadsLessonFreeSoon
  3. Creating threads: Thread, Runnable and CallableLessonFreeSoon
  4. Thread lifecycle and statesLessonFreeSoon
  5. Daemon threads and prioritiesLessonPremiumSoon
  6. Interrupts and cancellationLessonPremiumSoon
  7. Thread basics: interview questions & scenariosInterview Q&APremiumSoon

Synchronization

Race conditions, monitors, wait/notify and producer–consumer.

  1. Race conditionsLessonFreeSoon
  2. synchronized and monitorsLessonFreeSoon
  3. ReentrancyLessonPremiumSoon
  4. wait(), notify() and notifyAll()LessonPremiumSoon
  5. Why wait() and notify() need synchronizedFree guide · already liveFree
  6. The producer–consumer problemLessonPremiumSoon
  7. Synchronization: interview questions & scenariosInterview Q&APremiumSoon

Java Memory Model

Visibility, reordering, happens-before, volatile and safe publication.

  1. Visibility and reorderingLessonPremiumSoon
  2. Happens-beforeLessonPremiumSoon
  3. volatileLessonPremiumSoon
  4. Safe publication and double-checked lockingLessonPremiumSoon
  5. final field semanticsLessonPremiumSoon
  6. Java Memory Model: interview questions & scenariosInterview Q&APremiumSoon

Atomics & CAS

Lock-free building blocks.

  1. Atomic classesLessonPremiumSoon
  2. Compare-and-swap and the ABA problemLessonPremiumSoon
  3. LongAdder and striped countersLessonPremiumSoon
  4. Atomics & CAS: interview questions & scenariosInterview Q&APremiumSoon

Locks

Explicit locks and when to use them.

  1. ReentrantLock and ConditionLessonPremiumSoon
  2. ReadWriteLockLessonPremiumSoon
  3. StampedLockLessonPremiumSoon
  4. Lock fairnessLessonPremiumSoon
  5. Locks: interview questions & scenariosInterview Q&APremiumSoon

Liveness

Deadlock, livelock, starvation and thread dumps.

  1. Deadlock detection and preventionLessonPremiumSoon
  2. Livelock and starvationLessonPremiumSoon
  3. Reading thread dumpsLessonPremiumSoon
  4. Liveness: interview questions & scenariosInterview Q&APremiumSoon

Executors & thread pools

ExecutorService, ThreadPoolExecutor internals and sizing.

  1. ExecutorService and thread poolsLessonPremiumSoon
  2. ThreadPoolExecutor internalsLessonPremiumSoon
  3. Rejection policiesLessonPremiumSoon
  4. Scheduled executorsLessonPremiumSoon
  5. Sizing thread poolsLessonPremiumSoon
  6. Executors & thread pools: interview questions & scenariosInterview Q&APremiumSoon

Coordination utilities

Latches, barriers, semaphores and phasers.

  1. CountDownLatchLessonPremiumSoon
  2. CyclicBarrierLessonPremiumSoon
  3. SemaphoreLessonPremiumSoon
  4. PhaserLessonPremiumSoon
  5. Coordination utilities: interview questions & scenariosInterview Q&APremiumSoon

Concurrent collections

ConcurrentHashMap internals, copy-on-write and blocking queues.

  1. How ConcurrentHashMap worksLessonPremiumSoon
  2. CopyOnWriteArrayListLessonPremiumSoon
  3. BlockingQueue implementationsLessonPremiumSoon
  4. Concurrent collections: interview questions & scenariosInterview Q&APremiumSoon

Async programming

Futures, CompletableFuture and Fork/Join.

  1. Future and CallableLessonPremiumSoon
  2. How CompletableFuture worksLessonPremiumSoon
  3. Fork/Join and work stealingLessonPremiumSoon
  4. Async programming: interview questions & scenariosInterview Q&APremiumSoon

ThreadLocal

Per-thread state and its pitfalls.

  1. ThreadLocal and InheritableThreadLocalLessonPremiumSoon
  2. ThreadLocal memory leaksLessonPremiumSoon
  3. ThreadLocal: interview questions & scenariosInterview Q&APremiumSoon

Modern concurrency

Virtual threads, structured concurrency and scoped values.

  1. Virtual threadsLessonPremiumSoon
  2. Structured concurrency and scoped valuesLessonPremiumSoon
  3. Modern concurrency: interview questions & scenariosInterview Q&APremiumSoon

Concurrency coding problems

Classic problems you may be asked to code live.

  1. Concurrency coding problemsPractice problemsPremiumSoon
  2. Concurrency coding problems: interview questions & scenariosInterview Q&APremiumSoon

Module interview question bank

Finish the module

Module interview question bank

Every interview question worth practising for Multithreading & Concurrency, grouped by topic, with model answers, how to say them and what-if follow-ups.

Being written: it grows as the topics in this module are finished

PremiumSoon