my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes yield or join Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "yield or join" Watch "yield or join" New topic
Author

yield or join

Asha Pathik
Ranch Hand

Joined: Feb 08, 2006
Posts: 143
i came across this question in K&B1.4 Threads chapter....

Which three guarantee that a thread will leave the running state?
A. yield()
B. wait()
C. notify()
D. notifyAll()
E. sleep(1000)
F. aLiveThread.join()
G. Thread.killThread()

answer is B, E, and F.

B and E are fine but for F the explanation was based on the assumption that aLiveThread is alive. But then can't we say that option A is also correct if we assume there are some threads of same priority as the current thread in runnable state.

Plz help ...

Asha


SCJP 1.5
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

Well, I think the key is the word "guarantee". yield is more of a suggestion to the scheduler, and as you pointed out, there might not even be other threads to yield to. That aLiveThread is a live thread is implied by the variable name. That's more of a K&B thing than an exam thing. In a real program, aLiveThread may be in different states at different times, but in a K&B self-test, you can assume it is what it says it is.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: yield or join
 
Similar Threads
join() mock exam question
yield();
threads
Question from k&B's masterexam about yield()???????
Does a thread always move to the ready state if yield method is called?