public class Yield extends Thread {
public void run() {
//to stop thread 0
Thread.yield();
for (int i = 0; i < 5; i++) {
System.out.println(i + ":" + Thread.currentThread().getName());
}
}
public static void main(String[] args) {
Yield y1 = new Yield();
y1.start();
//to stop main method and other thread get a chance to execute
Thread.yield();
for (int i = 0; i < 5; i++) {
System.out.println(Thread.currentThread().getName() + ":" + i);
}
}
}