After invoking the wait method on an Object, Obj1, a Thread, T1, will remain in the wait set of Obj1 until which of the following occurs? a. Another Thread invokes the notify method on the Object, Obj1, and T1 is selected to move out of the wait set. b. Another Thread invokes the notifyAll method on the Object. c. Another Thread invokes the resume method on Thread T1. d. Another Thread interrupts Thread T1. e. The priority of Thread T1 is increased. f. A specified timeout period has elapsed. g. Another Thread invokes the join method on Thread T1. h. None of the above. Answer : a b d f Can someone explain why b? (b) Notify All does not garuntee that this waiting thread will not wait any more right...because another thread could me chosen instead of T1. Shouldnt the choice say "Another Thread invokes the notifyAll method on the Object and T1 is selected to move out of the wait set"?
Hey! It compiles! Ship it!
posted 15 years ago
Ah, I got this from the JLS
Some other thread invokes the notify method for that object and thread T happens to be the one arbitrarily chosen as the one to notify. Some other thread invokes the notifyAll method for that object. If the call by thread T to the wait method specified a timeout interval, the specified amount of real time has elapsed.
So the answer definately complies with that. Infact just read another quote from Kathy / Bert which says
In most scenarios, it's preferable to notify all of the threads that are waiting on a particular object. If so you can use notifyAll() on the object to let all the threads rush out of the waiting area and back to runnable.
I guess I carelessly assumed that only 1 thread was picked to go to runnable and then to running state, but indeed, all go into runnable, and then 1 to running state! Sorry, my bad!!