Hello Michael Lin,
You want to know that why you can nto use interrupt() in your code to call a particular waiting thread. I will try to explain you some points and hope it will solve your query.
First, different monitor states are: READY , RUNNING, SEEKING LOCK, A running thread can go to WAITING.
A thread that calls wait() releases the virtual CPU; at the same time, it releases the lock. It enters a pool of waiting threads, which is managed by the object whose wait() method got called. Every object has such pool.
It remains in WAITING until it has been notify() or notifyAll() or timeout or interrupt. When any one of these thing happen thread goes into SEEKING LOCK stage. Waiting their to obtain a lock. Once it obtain a lock it goes into READY state and when CPU gives time it start RUNNING.
Question is What happens when there is more than one thread waiting for notification/lock? Which thread actually gets the notification when notify(), notifyAll()is called?
The answer is that it depends: the
java specification dosen't define which thread gets notified. Which thread actually receives the notification varies based on several factors, including the implementation of the Java virtual machine and scheduling and timing issues during the execution of the program. There is no way to determine, even on a single platform, which of multiple threads receives the notification.
The interrupt() method is a method of the Thread class, and it is used by one thread to signal another thread: it is possible (although it dosen't really make sense) for a thread to interupt itself.
Calling interrupt() causes a thread to go into pool of waiting thread.
Therefor E is the correct answer because calling notify(), notifyAll() or interrupt() just put the waiting thread into SEEKING LOCK stage. And their is no way to specify which thread will get the lock.
Regards
Raj.