When the compiler's not happy, ain't nobody happy...
"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
Given the following run method of a thread, which are the ways in which a thread will surely come out of the waiting state ? (Choose all that apply)
code:
--------------------------------------------------------------------------------
public void run(){ synchronized(this){ try{ wait(5000); } catch(InterruptedException ie){} }}
--------------------------------------------------------------------------------
a) Another thread which owns the lock of the object invokes notify();
b) Another thread which owns the lock of the object invokes notifyAll();
c) Compilation fails.
d) The time period of 5 seconds has elapsed.
e) Another thread invokes join() on the thread.
f) Another thread invokes interrupt() on the thread.
g) Another thread invokes resume() on the thread.
h) An exception is thrown at runtime.
"Know where to find the solution and how to use it - that's the secret of success."
SCJP 5.0 (100%)<br />SCWCD (getting ready...)
Read the question carefully. The question is which thread will surely ...
Even if notify() is invoked on an object, a thead in waiting state to acquire monitor will not get object monitor unless the thread that invoked notify() has finished execution and the current thread has been selected to acquire lock. Hence the correct answer is d and f. Let me know if this helps.
"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
I've never won anything before. Not even a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|