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

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>();
        Semaphore s = new Semaphore(4);
11
        //Create some threads
Luca Arrotta's avatar
Luca Arrotta committed
12 13 14 15 16
        for (int i=0; i<10; i++) {
            MyThread mt = new MyThread(r, i, s);
            threads.add(mt);
        }

17
        //Start all the threads
Luca Arrotta's avatar
Luca Arrotta committed
18 19 20 21 22 23
        for (Thread t: threads) {
            t.start();
        }
    }
}