Coordinating Threads with join : Thread Join « Thread « SCJP






The Thread that calls the join method of another Thread waits for the other Thread to die before proceeding. 


public class MainClass implements Runnable {
  public static void main(String[] args) {
    MainClass jt = new MainClass();
    try {
      jt.t.join();
      System.out.println("after join");
    } catch (InterruptedException ex) {
      System.out.println("main exception:" + ex);
    }
  }

  Thread t;

  public MainClass() {
    t = new Thread(this);
    t.setPriority(Thread.MIN_PRIORITY);
    t.start();

  }

  public void run() {
    ;
  }
}
after join








7.5.Thread Join
7.5.1.Coordinating Threads with join