Which of the following will definitely stop a thread from executing: wait() notify() yield() suspend() sleep() my ans is wait(),suspend(),sleep() but Jxam says yield() is also correct.am i missing something Thanks Hima
I think yield() is, technically, a correct answer since calling yield() causes the currently running thread to return to the ready state and allows the VM to decide which thread to continue with. This is not to say that that the VM will not possibly pick the same thread that just yielded and continue (to the eye of the suer) as if nothing had happened. I suppose the point that they are after is that the running thread must stop executing for some period of time, even if that thread is re-chosen by the VM. This seems like a loaded, if not poorly worded question.
yeah! yield will cause thread itself give up the CPU time and turned to ready status until JVM re-call it run.it is "run"->"ready",but also stop execute
Actually, yield() is just a suggestion made to the thread scheduler that the current thread is not doing anything very interesting at the moment, and if it wants, it can go ahead and run a different thread. Since it's just a suggestion, there's no guarantee about the behavior on a particular implementation of a JVM. In fact, on a multiple processor system, a good thread scheduling algorithm will just ignore your yield() call, since it can do a far better job of thread balancing that you can as a programmer. So, it's not correct to say that "calling yield() will definately stop a thread from executing."
Rob
SCJP 1.4
I'm so happy! And I wish to make this tiny ad happy too:
a bit of art, as a gift, that will fit in a stocking