GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on threads" Watch "Question on threads" New topic
Author

Question on threads

majohnad majohnad
Greenhorn

Joined: Jan 01, 2003
Posts: 24
Under what circumstances might you use the yield method of the Thread class
1) To call from the currently running thread to allow another thread of the same or higher priority to run
2) To call on a waiting thread to allow it to run
3) To allow a thread of higher priority to run
4) To call from the currently running thread with a parameter designating which thread should be allowed to run
My Answer is 2. is it correct? If not how? pls explain....
Which is the correct Answer.


zxjohn
frank fan
Greenhorn

Joined: Apr 12, 2003
Posts: 8
ans 2 is surely wrong.because we should use notify or notifyAll method to tell the the thread in the waiting queue.So a thread(using notify) or all threads(using notifyALL) will be in the ready queue


Just do it
frank fan
Greenhorn

Joined: Apr 12, 2003
Posts: 8
ans 2 is surely wrong.because we should use notify or notifyAll method to tell the the thread in the waiting queue.So a thread(using notify) or all threads(using notifyALL) will be in the ready queue
Frank
Bryan Helm
Greenhorn

Joined: Apr 07, 2003
Posts: 20
Answer is one, sort of. However, you do not have to call yield to allow a higher priority thread to run; the VM can run it whenever it pleases. Yield does allow a same priority thread to run, but does not guarantee a different thread will run, or that any attention will be paid to the yield call at all.
Praveen Kumar Mathaley
Ranch Hand

Joined: Apr 14, 2003
Posts: 45
here are my views
1)To call from the currently running thread to allow another thread of the same or higher priority to run
-->This is not correct completely as any runnable thread will get it's turn to run.
2) To call on a waiting thread to allow it to run
-->what does the waiting thread here imply, if it means any thread that's ready to be run then it's the correct answer,
else if it's the thread waiting implicitly by making a call to wait method then it can resume only when the other Thread which holds lock will call notify or notifyAll method
3) To allow a thread of higher priority to run
--> This is wrong
4) To call from the currently running thread with a parameter designating which thread should be allowed to run
This is obviously wrong.
Here if the author implies that the waiting thread means any thread that's in the state of ready to run then it's the correct answer
else rest are wrong.
 
GeeCON Prague 2014
 
subject: Question on threads