Multiple choice technology programming languages

A monitor called nik has 3 threads, having same priority, in its waiting pool; How can we notify one of the threads, named 'thread1' to move from Waiting state to Ready State?

  1. Execute notify(thread1); from within synchronized code of mon.

  2. Execute mon.notify(thread1); from synchronized code of any object.

  3. Execute thread1.notify(); from synchronized code of any object.

  4. Execute thread1.notify(); from any code(synchronized or not) of any object.

  5. You cannot specify which thread will get notified.

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

Java's notify() and notifyAll() methods do NOT allow specifying which thread to notify. The JVM arbitrarily selects one thread from the wait pool. You cannot control which specific thread gets notified.

AI explanation

Object.notify() (or notifyAll()) wakes up a thread waiting on that object's monitor, but the JVM chooses which single thread to wake from the wait set — there is no API to target a specific thread by name or reference for notification. thread1.notify() would attempt to notify on thread1's own monitor, not mon's, so it wouldn't even affect the threads waiting on mon. This is why you cannot deterministically choose which waiting thread gets notified.