What is the difference between `notify()` and `notifyAll()` in Java object monitors?

Java Professional Medium

Java Professional — Medium

What is the difference between `notify()` and `notifyAll()` in Java object monitors?

Key points

  • `notify()` wakes one thread; `notifyAll()` wakes all
  • Prevents potential thread starvation
  • `notify()` is non-deterministic; `notifyAll()` is deterministic

Ready to go further?

Related questions