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

Ambiguous Thread Question?

Don Wood
Ranch Hand

Joined: Dec 05, 2003
Posts: 65
From the Marcus Green exam 3:

Given a reference called
t
to a class which extends Thread, which of the following will cause it to give up cycles to allow another thread to execute.
1) t.yield();
2) Thread.yield();
3) yield(100); //Or some other suitable amount in milliseconds
4) yield(t);

The answers given are 1 and 2 but I find the question troubling. The question does not state whether t is a reference to the current thread or another thread so I took it to mean that t could be a reference to another thread. If so, none of the answers are correct.
Perhaps I am missing something but the question seems to be unclear in its intent.
Are we expected to see our way through ambiguously worded questions on the real exam?
Phil Rhodes
Ranch Hand

Joined: Dec 27, 2003
Posts: 65
My take is that yes, some of the questions are a little ambigous. As I recall from my SCJP exam however, I don't remember there being more than 1 or 2 questions that I thought were questionable / ambigous...
Also the real exam questions were, in general, easier than the chapter review questions in the Kathy Sierra - Bert Bates book. If you have access to that book, I'd say that if you can answer most of the review questions in it without difficulty, you'll have no problem with the real exam.


A+, Network+, SCJP, SCWCD<br />preparing for SCBCD, SCEA, CompTIA I-Net+
Peter Kleczka
Greenhorn

Joined: Feb 09, 2003
Posts: 18
Yield is a static method. In fact the Javadoc says that yield()
Causes the currently executing thread object to temporarily pause and allow other threads to execute.
So it doesn't matter if t is an instance and we say t.yield() v.s. Thread.yield(). It will always act on the "currently executing thread" no matter where we call it from.
HTH
Don Wood
Ranch Hand

Joined: Dec 05, 2003
Posts: 65
Peter,
Just as you point out, yield only works on the current thread. This is the reason that I believe the question is poorly worded. It is not clear from the question whether t refers to the current thread or another thread. If t refers to another thread then all the answers are wrong.
If the question had made it clear that t refers to the current thread then I would agree that answers 1 and 2 are correct.
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
This question is problematic and was recognized as such by Marcus himself a long time ago. He suggested that instead of "will" one read "can" for clarity. Another problem with it is that yield doesn't guarantee that the current thread actually will give up its cycles. I wonder why the questions don't get updated on his site.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Ambiguous Thread Question?