Thread Yield method in Java

In java, yield()  method  temporarily pause  the currently executing thread object  and allow other threads to execute.

class A extends Thread {
    public void run() {
        for (int i = 1; i <= 5; i++) {
            if (i == 2) yield();
            System.out.println("A" + i);
        }
        System.out.println("Exit from A");
    }
}
class B extends Thread {
    public void run() {
        for (int i = 1; i <= 5; i++) {
            System.out.println("B" + i);
        }
        System.out.println("Exit from B");
    }
}
public class xyz {
    public static void main(String args[]) {
        A a = new A();
        B b = new B();
        a.start();
        b.start();
    }
}
A1
A2
A3
A4
A5
Exit from A
B1
B2
B3
B4
B5
Exit from B