First without join()


 

public class jointest extends Thread{
   public jointest(String s) {
      super(s);  
  }
   public static void main(String[] args) {
      Thread t=new jointest("joinThread");
      t.start();
     /* try {t.join();
        }catch(InterruptedException e) {
           System.out.println("interupted");
        } */
       System.out.println(Thread.currentThread().toString());
      }
   public void run() {
            System.out.println(Thread.currentThread().toString());
   }

}//jointest

 

OUTPUT:

D:\jdk1.3\bin\java.exe jointest

Thread[joinThread,5,main]

Thread[main,5,main]


Now with join()


public class jointest extends Thread{
   public jointest(String s) {
      super(s);  
  }
   public static void main(String[] args) {
      Thread t=new jointest("joinThread");
      t.start();
     try {t.join();
        }catch(InterruptedException e) {
           System.out.println("interupted");
        }
       System.out.println(Thread.currentThread().toString());
      }
   public void run() {
            System.out.println(Thread.currentThread().toString());
   }

}//jointest

 

OUTPUT:

D:\jdk1.3\bin\java.exe jointest

Thread[joinThread,5,main]

Thread[main,5,main]