In the following code, when using the .yield() method, the main method doesn't appear to be a thread. So, Is the yield happening between methods that are calling the same class/object method i.e. System.out.print?
One call to system.out.print is yielding to the call to the same method in the main class?
// program to demonstrate the yield() method of Thread class class YieldClass extends Thread{ public void run(){ // run method overrides Thread run() for(int i = 0; i < 5; i++){ // loop 5 times when method called System.out.println("Thread 2 is running."); Thread.yield(); // } } } public class ThreadYield{ public static void main(String args[]){ YieldClass t = new YieldClass(); t.start(); for(int i = 0; i < 5; i ++){ System.out.println("Main Thread is running."); } } }