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.
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.
Originally posted by Jose Botella:
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.