If I have several threads in the runnable pool and one
thread which is running and has priority higher than all those in the pool, what will happen when I invoke yield() method on the running thread?
Will it
1) Leave the running state, return to runnable pool and since it has priority higher than all the rest be elected again, OR
2) It won't even bother changing state since JVM knows that the rest of the threads in the pool have lower priorities?
I have understood this to be a step-by-step process (first solution) but it doesn't seem to be so...?
Some quotes from the K&B book:
pg. 513: "What yield() is supposed to do is make the currently running thread head back to runnable to allow other threads of the same priority to get their turn."
pg. 553: "The yield() method is not guaranteed to cause a thread to leave the running state..."
So will it leave to get back or it won't leave at all?
I'd appreciate if someone could clarify it a bit.
TIA,
Bojan