| Author |
Thread doubt
|
Marcelo Ortega
Ranch Hand
Joined: May 31, 2005
Posts: 519
|
|
Question: Thread Z holds the lock on object A. Thread X is blocked inside a wait call on ObjectA. What allows thread X to become runnable? A. Thread X is interrupted. B. Thread X is interrupted. C. Thread X�s wait() times out. D. Thread Z calls Thread.sleep(100); E. Thread Z releases the lock on A and calls the notify() method on thread X F. Thread Z releases the lock on A and calls the notifyAll() method on objectA. Answer given: F I thought it would of been C and F??? Can anyone clarify this?
|
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA
Live life to an interface, not an implementation!
|
 |
raghu babu
Ranch Hand
Joined: Jul 05, 2005
Posts: 60
|
|
Marzo, A and B has same text, but I'm thinking A,C and F instead just F. I hope someone would clarify our understanding.
|
 |
Marcelo Ortega
Ranch Hand
Joined: May 31, 2005
Posts: 519
|
|
|
Oh sorry thats a typo.
|
 |
Santana Iyer
Ranch Hand
Joined: Jun 13, 2005
Posts: 335
|
|
Marzo, Thread Z holds the lock on object A. Thread X is blocked inside a wait call on ObjectA. C. Thread X�s wait() times out. No, as even if X's wait times out X remains in non runnable state because it must acquire lock on object A which is hold by thread Z, after acquiring lock on object A, thread X can go to runnable state. Other example is say when we call notify on object A in thread Z, now thread waiting for object lock (Thread X) does not go directly to Runnable it must wait and acquire lock on object A than only it can go to runnable. (calling notify does not immediately release lock, only after synchronized method or block completes than only lock is released on object A by thread Z, now X thread can acquires lock and can make transition to runnable state). Hope this helps, bye.
|
 |
 |
|
|
subject: Thread doubt
|
|
|