package threadPool; public class ComputerThread extends Thread { Repository tasks = null; Repository results = null; Compute function = null; public ComputerThread(Repository tasks, Repository results, Compute function) { this.tasks = tasks; this.results = results; this.function = function; return; } public void run() { while (true) { T task = tasks.extract(); try { int random = ((int) (Math.random() * 5000.00)); System.out.println("Thread " + this.getName() + " inizio calcolo"); sleep(random); S result = function.compute(task); System.out .println("Thread " + this.getName() + " fine calcolo"); results.insert(result); } catch (InterruptedException e) { System.out.println("Calcolo del thread " + this.getName() + " interrotto!"); } System.out.println("Thread " + this.getName() + " computed task " + task); } } }