Locks

Locks in Java: what synchronized guarantees, which object it locks, reentrancy, ReentrantLock, and what a lock cannot protect.

  • 9 cards
  • 5 questions
  • About 9 min
  • Intermediate to Advanced
Share

Locks: the tool that lets only one thread at a time into a piece of code, and that is the only everyday fix when correctness depends on more than one field. synchronized does two jobs, excluding other threads and publishing writes, and almost everyone knows only the first. It covers what synchronized locks, the visibility guarantee, static methods, reentrancy, ReentrantLock, and why synchronising every method is not enough. It leaves out read-write locks and StampedLock.

Contents

9 cardsnot started