• 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

Please, help! I'm a bit confused :)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marcus Green's Mock Exam 3
#44
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);
Answers: 1 and 2 (!)
Correct me if I'm wrong, but we have no chance to garantee that this call "will cause giving up cycles ..."
www.javaprepare.com: Shot tips.
".yield() - if there're no threads of the same priority call is ignored."
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please refer to the following discussion dealing with Thread.yield:
https://coderanch.com/t/239572/java-programmer-SCJP/certification/Thread-yield-Cowgirl
 
Tim Kamen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot, Valentin!
I got it time before . That thread is like a discussion, without strict and sole answer.
Will you help me with my #44 in terms of exam, please? Did I miss something important in the question, or my answer is correct?
[ October 21, 2002: Message edited by: Tim Kamen ]
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The API for java.lang.Thread.yield states


Causes the currently executing thread object to temporarily pause and allow other threads to execute.


Moreover, the yield method is static, and thus, a reference of a thread is of no use. It is the scheduler's job to decide if the currently executing thread will yield the CPU to another thread or not. The effect of the yield method is really implementation-dependent as the API does not specify any specific behavior. It does not mention that only threads with the same priority will get the chance to run.
The answers provided by Marcus are both correct, however, I would rephrase the question as follows:
"Given a reference called t to a class which extends Thread, which of the following may cause the scheduler to allow another thread to execute."
 
Tim Kamen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, thanks again. That's exactly what I'd like to hear
 
Talk sense to a fool and he calls you foolish. -Euripides A foolish tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic