Main.java 497 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
import java.util.ArrayList;
import java.util.Random;

//Utilizzo di un semaforo "fatto a "
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);
	  //create some threads
	  for (int i=0; i<10; i++) {
		  MyThread mt = new MyThread(r, i, s);
		  threads.add(mt);
	  }
	  
	  //start all the threads
	  for (Thread t: threads) {
		  t.start();
	  }
  }
}