Implementazione della classe Monitor 2
// OVERVIEW: un Monitor è un oggetto che può contenere un messaggio (stringa) e
// che permette di trasferire una sequenza di messaggi in modo sincrono da un
// thread produttore ad un thread consumatore
private boolean pieno = false;
private boolean stop = false;
synchronized String receive ( ) {
// EFFECTS: se this è pieno, restituisce l’ultimo messaggio ricevuto e diventa
// vuoto; altrimenti il thread viene sospeso finché this non diventa pieno
if (!pieno) try {wait ( ); } catch (InterruptedException e) { }
synchronized boolean finecomunicazione ( ) {
// EFFECTS: restituisce true se this è vuoto ed ha chiuso la comunicazione con il