Multiple choice technology programming languages

A number of threads of the same priority have relinquished the lock on a monitor and are in a waiting state after having called the wait() method of the object. A new thread enters the monitor and calls the notifyAll() method of the meonitor. Which of these threads will be the first one to resume?

  1. The thread that has been waiting the longest.

  2. The thread that was the last one to to exit the monitor.

  3. You can never be sure which thread will get to run first.

  4. The the first thread that called the wait() method

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

When notifyAll() awakens waiting threads, the JVM does not guarantee any ordering; threads compete for the monitor and any of them may proceed first. Hence the correct answer is that you can never be sure which thread runs first, matching the marked option.