Launch many programs using Thread and use join() to wait for the completion. : Wait « Threads « Java






Launch many programs using Thread and use join() to wait for the completion.

 

class Main2 {
  public static void main(String arg[]) {
    System.out.println("Main2");
  }
}

public class Main {
  public static void main(String arg[]) throws Exception {
    System.out.println("Main");
    Thread t1 = new Thread() {
      public void run() {
        Main2.main(new String[] {});
      }
    };
    t1.start();
    t1.join();
    System.out.println("Main again");
  }
}

   
  








Related examples in the same category

1.Wait the for the completion of a thread
2.Wait for the threads to finish
3.Demonstrate join().
4.A simple demonstration of wait() and notify().
5.Suspend, resume, and stop a thread.
6.Waiting on an object