Causes the currently executing thread object to temporarily pause and allow other threads to execute.
A thread can voluntarily yield the CPU without going to sleep or some other drastic means by calling the yield method. The yield method gives other threads of the same priority a chance to run. If there are no equal priority threads that are runnable, then the yield is ignored.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Whatever doesn't kill us ...<br />Is probably circling back for another try.<br />SCJP 1.4
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Co-Author of Head First Design Patterns
Just a Jini girl living in a J2EE world.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Co-Author of Head First Design Patterns
Just a Jini girl living in a J2EE world.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
SCJP2. Please Indent your code using UBB Code
I emphasize "no guarantee" because if I were studying for the exam, I would be very, very careful to understand what is and is not absolutely guaranteed by the language specification (or Gosling in any context), regardless of any results you actually achieve (or that anyone else recommends).
The point of the exam is to verify that you truly know how to guarantee that your code is portable.
Same deal with the Developer exam... if the assessor sees that your code, while running fine on the test machines, is relying on non-guaranteed behavior, then there's a big problem.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Originally posted by Jose Botella:
<snipped>
a) it yields only to threads of the same priority
For the exam I think option a is safer.
I would use yield to avoid starvation in an application where all the threads has the same priority. Some systems would choose one of threads and would execute it untill, well, it yields or ends with it.
Co-Author of Head First Design Patterns
Just a Jini girl living in a J2EE world.
SCJP2. Please Indent your code using UBB Code
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>