Strumenti Utente

Strumenti Sito


lpr-b-2007-2008:maintermina
package threadPoolConTerminazione;
 
 
public class ProvaThreadPool {
 
	public static void main(String[] args) {
 
		final int N = 8;
		final int T = 4; 
 
		Repository<Integer> tasks = new Repository<Integer>();
		Repository<Integer> results = new Repository<Integer>();
		FunzioneSemplice funz = new FunzioneSemplice();
		ComputerThread[] ct = new ComputerThread[T];
 
		Generatore generatore = new Generatore(N,tasks);
		Stampatore<Integer> stampatore = new Stampatore<Integer>(results);
		generatore.start();
		stampatore.start();
 
		System.out.println("Creazione dei thread nel pool ");
		for(int i=0; i<T; i++) {
			ct[i] = new ComputerThread<Integer,Integer>(tasks, results, funz);
			ct[i].start();
		}
		System.out.println("Attesa terminazione thread del pool ...");
		for(int i=0; i<T; i++) {
			try {
				ct[i].join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		System.out.println("Tutti i thread del pool sono terminati\nTerminazione Stampatore ...");
		stampatore.interrupt();
		System.out.println("Terminazione main");
		return;		
	}
 
}
lpr-b-2007-2008/maintermina.txt · Ultima modifica: 19/09/2008 alle 14:08 (16 anni fa) (modifica esterna)