Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. public class ThreadJoin {
  2.  
  3.     public static void main(String[]args) throws InterruptedException{
  4.        
  5.         DemoThread t0 =new DemoThread();
  6.         DemoThread t1 =new DemoThread();
  7.         DemoThread t2 =new DemoThread();
  8.         t0.start();
  9.         t0.join();
  10.         t1.start();
  11.         t2.start();
  12.        
  13.     }
  14. }
  15.  
  16. class DemoThread extends Thread{
  17.    
  18.     public void run(){
  19.         for(int i =0 ;i <5 ;i++){
  20.             System.out.println(this.getName()+":"+i);
  21.             try {
  22.                 Thread.sleep(1000);
  23.             } catch (InterruptedException e) {
  24.                 e.printStackTrace();
  25.             }
  26.         }
  27.     }
  28. }