Untitled
class MyThread extends Thread { public void run() { System.out.println("Thread started"); for (int i = 0; i <= 5; i++) { System.out.println("Current Thread :"+Thread.currentThread().getName()+i+""); try { Thread.sleep(1000); } catch (InterruptedException e) { System.out.println("Interrupt occurred"); } } System.out.println("Thread Ended"); } } class Result2 { public static void main(String[] args) { MyThread t1 = new MyThread(); MyThread t2 = new MyThread(); MyThread t3 = new MyThread(); t3.start(); try{ t3.join(); } catch(InterruptedException e) { System.out.println("Exception caught"); } t1.start(); try { t1.join(); } catch(InterruptedException e) { System.out.println("Exception caught"); } t2.start(); } }
Leave a Comment