aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus Mock Question 24 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 "Marcus Mock Question 24" Watch "Marcus Mock Question 24" New topic
Author

Marcus Mock Question 24

Matt Ghiold
Ranch Hand

Joined: Feb 24, 2002
Posts: 213
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

Marcus says the answer is 1, but I think 3 is also true, it may not happen, but it's still a viable reason.
Thoughts?
-Matt


-Matt<br /> SCJP2<br /> SCJD
swapna sivaraju
Ranch Hand

Joined: Jan 18, 2002
Posts: 75
HI
Actually the behaviour of yield method is platfrom dependent so its unpredicatble what it does...it may allow some other thread with higher prioprity to run and itself go into runnable state or may not even do that...
Now,1 seems correct as it says that its called from currently running thread which is true. but in 3 case its not very clear which thread is calling it and it looks as if the statement is sure that the Higher priority thread will be invoked by yeidling(which is not always the case).
Hope this helps.
swapna


SCPJ2
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Actually the doc is not really accurate about this but the specification of yield is really to yield for same-priority threads.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Matt Ghiold
Ranch Hand

Joined: Feb 24, 2002
Posts: 213
Well I guess if it comes up in the exam, it will tell me how many correct answers there are, so I won't have to worry about it, I knew 1 was correct, but at the same time, I felt 3 was correct even though it wasn't guranteed it was still a viable option.
-Matt
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hello Ranchers
It has been a while since I was here, but I am checking on you guys.
I do not think yield is platform dependent. Yield is just a way to check if there are other threads with same or higher priority waiting and you want to give that other thread a chance, rather than your thread consuming the CPU cycle.
Hope this Helps.
Amish
Originally posted by swapna sivaraju:
HI
Actually the behaviour of yield method is platfrom dependent so its unpredicatble what it does...it may allow some other thread with higher prioprity to run and itself go into runnable state or may not even do that...
Now,1 seems correct as it says that its called from currently running thread which is true. but in 3 case its not very clear which thread is calling it and it looks as if the statement is sure that the Higher priority thread will be invoked by yeidling(which is not always the case).
Hope this helps.
swapna
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
From the Java tutorial:

In addition, a given thread may, at any time, give up its right to execute by calling the yield method. Threads can only yield the CPU to other threads of the same priority--attempts to yield to a lower priority thread are ignored.
swapna sivaraju
Ranch Hand

Joined: Jan 18, 2002
Posts: 75
Thank u Amish and Valentin...got to do some more reading on this!I got the thing very wrong!!

swapna
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by swapna sivaraju:
Thank u Amish and Valentin...got to do some more reading on this!I got the thing very wrong!!

swapna

Hi
Check on Bruce Eckel's Thinking in Java for good examples about yield. He represents it nicely.
Hope this helps!
-Amish
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
Note that the question asks "Under what circumstances might you use the yield method of the Thread class"
Option 3 might be an answer to a quesiton such as
"Might a Thread of a higher priority run when the yield method is called",
but it asks under what circumstances might you use the yield method (ie you the programmer use it, rather than what might happen if you use it). Because of the platform dependent nature of Threading and the inconsistent way that priorities work. The programmers exam will question you on issues relating to the platform dependent nature of Threading. I try to keep my questions as unambiguous as possible and I know this comes close to the edge, but understanding the implications of when and where to call the yield method is important.


SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
Matt Ghiold
Ranch Hand

Joined: Feb 24, 2002
Posts: 213
Thank's Marcus! I appreciate the insite, because I am sure it will come in very handy when I take the exam.
-Matt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Marcus Mock Question 24