lpr-b:threadcomputecalcolatore
no way to compare when less than two revisions
Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
| — | lpr-b:threadcomputecalcolatore [05/10/2007 alle 13:00 (18 anni fa)] (versione attuale) – creata Marco Danelutto | ||
|---|---|---|---|
| Linea 1: | Linea 1: | ||
| + | <code java> | ||
| + | package threadPool; | ||
| + | public class ComputerThread< | ||
| + | |||
| + | Repository< | ||
| + | |||
| + | Repository< | ||
| + | |||
| + | Compute< | ||
| + | |||
| + | public ComputerThread(Repository< | ||
| + | Compute< | ||
| + | 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(" | ||
| + | + " inizio calcolo" | ||
| + | sleep(random); | ||
| + | S result = function.compute(task); | ||
| + | System.out | ||
| + | .println(" | ||
| + | results.insert(result); | ||
| + | } catch (InterruptedException e) { | ||
| + | System.out.println(" | ||
| + | + " interrotto!" | ||
| + | } | ||
| + | |||
| + | System.out.println(" | ||
| + | + task); | ||
| + | |||
| + | } | ||
| + | } | ||
| + | |||
| + | } | ||
| + | </ | ||
lpr-b/threadcomputecalcolatore.txt · Ultima modifica: 05/10/2007 alle 13:00 (18 anni fa) da Marco Danelutto
