/* Printing threads yield after printing a number */ public class Test3 { static final int NUM_THREADS = 10; public static void main(String[] argv){ MyThread3[] myThreads = new MyThread3[NUM_THREADS]; for (int i=0; i < NUM_THREADS; i++) myThreads[i] = createThread(i); for (int i=NUM_THREADS; i > 0;) myThreads[--i].start(); try { myThreads[0].join(); } catch (InterruptedException e){ return; } System.out.println(); } public static MyThread3 createThread(int i){ return new MyThread3(new Integer(i).toString()); } } class MyThread3 extends Thread{ static final int NUM_PRINTS = 30; MyThread3(String s){ super(s); } public void run(){ for (int i=0; i < NUM_PRINTS; i++){ System.out.print(getName()); yield(); } } }