Implementazione della classe Monitor 1
// 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 void send (String msg) {
// EFFECTS: se this è vuoto, riceve msg e diventa pieno; altrimenti il thread
// viene sospeso finché this non diventa vuoto
if (pieno) try {wait ( ); } catch (InterruptedException e) { }
synchronized void finemessaggi ( ) {
// EFFECTS: this chiude la comunicazione con il produttore
// REQUIRES: il thread produttore non può invocare altri metodi dopo questo