Doubt:
Can't a thread be prevented from execution if
a) yielded (entering Ready state)
b) suspended (entering Suspended state)
c) put into sleep (entering Sleeping state)
d) blocked due to I/O operations (entering Blocked state)
e) due to wait() call (entering the monitor's waiting pool and in the Waiting state)
f) pre-empted (if OS supports pre-emptive scheduling)
g) fail to acquire the monitor's lock (entering Seeking Lock state)
I think that all the above will move a thread from running state to an intermediate state. Please do guide me...
Also there is a question in Marcus's tutorial:
Which of the following are recommended ways a Thread may be blocked?
1) sleep()
2) wait/notify
3) suspend
4) pause
Answer given is sleep() and wait/notify. Is this answer correct? Why suspend() is not the answer? (since it is deprecated or any other reason).
What do they mean by "pause"?
SCJP2. Please Indent your code using UBB Code
SCJP2. Please Indent your code using UBB Code
Originally posted by Jose Botella:
to Val, Thank you for the cumpliment. I keep saying the same about you in all my posts as we accorded ;-)
These methods doesn't abandon the running state. When a thread receives one of these messages it is blocked. It becames runnable to enter the competition to be chosen by the scheduler to be runned again. Also the thread that call these methods on another thread doesn't abandon the running state until it calls wait on itself. That is why the monitors in Java are called Signal and Continue (notify and continue executing untill wait).
The following methods may or may not leave the running state:
3) notify()/notifyAll() [may enter seeking lock state, if it fails to acquire lock]
SCJP2. Please Indent your code using UBB Code
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
|