Check out example codes for "thread yeald java". It will help you in understanding the concepts better.

Code Example 1

// Java program to illustrate yield() method 
// in Java 
import java.lang.*; 
  
// MyThread extending Thread 
class MyThread extends Thread 
{ 
    public void run() 
    { 
        for (int i=0; i<5 ; i++) 
            System.out.println(Thread.currentThread().getName() 
                                + " in control"); 
    } 
} 
  
// Driver Class 
public class yieldDemo 
{ 
    public static void main(String[]args) 
    { 
        MyThread t = new MyThread(); 
        t.start(); 
  
        for (int i=0; i<5; i++) 
        { 
            // Control passes to child thread 
            Thread.yield(); 
  
            // After execution of child Thread 
            // main thread takes over 
            System.out.println(Thread.currentThread().getName() 
                                + " in control"); 
        } 
    } 
}

Learn ReactJs, React Native from akashmittal.com