public class MainClass { public static void main(String args[]) { MyThread t1 = new MyThread("t1"); MyThread t2 = new MyThread("t2"); t1.start(); t2.start(); } } class MyThread extends Thread { public void displayOutput(String s) { System.out.println(s); } public void run() { for (int i = 0; i < 10; ++i) { try { sleep((long) (3000 * Math.random())); } catch (Exception ex) { } displayOutput(getName()); } } public MyThread(String s) { super(s); } }