Java Programming - Threads - Discussion

12. 

Assume the following method is properly synchronized and called from a thread A on an object B:

wait(2000);

After calling this method, when will the thread A become a candidate to get another turn at the CPU?

[A]. After thread A is notified, or after two seconds.
[B]. After the lock on B is released, or after two seconds.
[C]. Two seconds after thread A is notified.
[D]. Two seconds after lock B is released.

Answer: Option A

Explanation:

Option A. Either of the two events (notification or wait time expiration) will make the thread become a candidate for running again.

Option B is incorrect because a waiting thread will not return to runnable when the lock is released, unless a notification occurs.

Option C is incorrect because the thread will become a candidate immediately after notification, not two seconds afterwards.

Option D is also incorrect because a thread will not come out of a waiting pool just because a lock has been released.


Vibhor said: (Jul 5, 2011)  
Please give me more explanation about this question.

Dinesh said: (Sep 24, 2013)  
Give me an explanation that how it works?

D.Raj said: (Jan 28, 2014)  
Either of the two events (notification or wait time expiration) will make the thread become a candidate for running again.

Ashish said: (Mar 7, 2014)  
If Thread A is notified first, can it get CPU turn before the expiration of 2 sec?

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.