Multiple choice technology programming languages

foo and bar are public references available to many other threads. foo refers to a Thread and bar is an Object. The thread foo is currently executing bar.wait(). From another thread, which statement is the most reliable way to ensue that foo will stop executing wait()?

  1. foo.notify();

  2. bar.notify();

  3. foo.notifyAll();

  4. Thread.notify();

  5. bar.notiFYAll();

  6. Object.notify();

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

Since thread foo is executing bar.wait(), it's waiting on bar's monitor. To wake it, you must call notify() or notifyAll() on the SAME object (bar). bar.notifyAll() is the most reliable as it wakes all waiting threads, ensuring foo stops waiting.