This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Ambiguous Thread Question?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Do not set lab on fire. Or this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic