Main.java 753 Bytes
Newer Older
1 2
package join;

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
import java.util.ArrayList;
import java.util.Random;

public class Main {

  public static void main(String arg[]) throws Exception {
	  Random r = new Random();
	  ArrayList<Thread> threads = new ArrayList<Thread>();
	  //create some threads
	  for (int i=0; i<100; i++) {
		  MyThread mt = new MyThread(r);
		  threads.add(mt);
	  }
	  System.out.println("All threads have been created.");
	  //start all the threads
	  for (Thread t: threads) {
		  t.start();
	  }
	  System.out.println("All threads have been started.");
	  System.out.println("Start waiting for all thread to finish...");
	  //wait all the thread to finish
	  for (Thread t : threads) {
		  t.join();
	  }
27
	  
28 29 30 31
	  System.out.println("...All thread finished!");
  }

}