lpr-b:threadtermina
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:threadtermina [05/10/2007 alle 18:15 (17 anni fa)] (versione attuale) – creata Marco Danelutto | ||
---|---|---|---|
Linea 1: | Linea 1: | ||
+ | <code java> | ||
+ | package threadPoolConTerminazione; | ||
+ | public class ComputerThread< | ||
+ | |||
+ | Repository< | ||
+ | Repository< | ||
+ | Compute< | ||
+ | |||
+ | public ComputerThread(Repository< | ||
+ | this.tasks = tasks; | ||
+ | this.results = results; | ||
+ | this.function = function; | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | public void run() { | ||
+ | while(true) { | ||
+ | T task = null; | ||
+ | try { | ||
+ | task = tasks.extract(); | ||
+ | } catch (EndOfStreamException e) { | ||
+ | System.out.println(" | ||
+ | return; // fine lavori | ||
+ | } catch (InterruptedException e) { | ||
+ | System.out.println(" | ||
+ | } | ||
+ | try { | ||
+ | int random = ((int)(Math.random() * 5000.00)); | ||
+ | System.out.println(" | ||
+ | sleep(random); | ||
+ | S result = function.compute(task); | ||
+ | System.out.println(" | ||
+ | results.insert(result); | ||
+ | } catch(InterruptedException e) { System.out.println(" | ||
+ | |||
+ | System.out.println(" | ||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ |
lpr-b/threadtermina.txt · Ultima modifica: 05/10/2007 alle 18:15 (17 anni fa) da Marco Danelutto