Joining a Thread :JAVA Programming by "Gopal Krishna"
// sleep method
public class thr4 extends Thread{ int i; public void run() { for (i=1;i<6;i++) { System.out.println(i); try { Thread.sleep(1000); } catch(Exception e) { System.out.println(e); } } } public static void main (String arg[]) { thr3 x1= new thr3(); thr3 x2= new thr3(); thr3 x3= new thr3(); x1.start(); try { x1.join(); } catch(Exception e) { System.out.println(e); } x2.start(); try { x2.join(); } catch(Exception e) { System.out.println(e); } x3.start();
} }
No comments:
Post a Comment