package threadPoolConTerminazione; import java.util.LinkedList; /** * classe che implementa il repository delle cose da calcolare * @author marcod */ public class Repository { private LinkedList ll = null; boolean eos = false; public Repository() { super(); ll = new LinkedList(); } /** * inserzione di un elemento nel pool * @param data il dato da inserire */ public synchronized void insert(T data) { ll.add(data); notify(); } /** * estrazione dell'elemento più vecchio dal pool * @return il dato più vecchio nel pool (rimosso) */ public synchronized T extract() throws EndOfStreamException, InterruptedException { while(ll.isEmpty()) { if(eos) { throw new EndOfStreamException(); } wait(); // se viene interrotta è per la interrupt allo Stampatore } T task = ll.remove(); return task; } public synchronized void eos() { eos = true; } }