public class JoinExample {

  public JoinExample() {
    Thread t1 = new Thread1();
    t1.start();
    System.out.println("Parent thread: waiting for child to finish");
    try { t1.join(); } catch (InterruptedException e) {}
    System.out.println("Parent thread: child has finished");
  }

  public static void main(String args[]) {
    JoinExample j = new JoinExample();
  }

  private class Thread1 extends Thread {
    public void run() {
      for (int i=0; i<5; i++) {
        System.out.println("Child thread: iteration"+i);
	try { Thread.sleep(1000); } catch (InterruptedException e) {}
      }
    } 
  }
}



