Main.java 862 Bytes
Newer Older
Luca Arrotta's avatar
Luca Arrotta committed
1 2 3 4 5 6 7 8 9 10 11
package join;


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>();
12
        //Create some threads
Luca Arrotta's avatar
Luca Arrotta committed
13 14 15 16 17
        for (int i=0; i<10; i++) {
            MyThread mt = new MyThread(r);
            threads.add(mt);
        }
        System.out.println("All threads have been created.");
18
        //Start all the threads
Luca Arrotta's avatar
Luca Arrotta committed
19 20 21 22 23
        for (Thread t: threads) {
            t.start();
        }
        System.out.println("All threads have been started.");
        System.out.println("Start waiting for all thread to finish...");
24
        //Wait all the thread to finish
Luca Arrotta's avatar
Luca Arrotta committed
25 26 27 28 29 30 31 32 33
        for (Thread t : threads) {
            t.join();
        }

        System.out.println("...All thread finished!");
    }

}