A seguir: Propriedades do Buffer Compartilhado Acima: Aula 11 - Modelos Anterior: Motivação
class Buffer {
private Queue buffer;
int n;
final int MAX = 10;
public Buffer() {
buffer = new Queue(MAX); n = 0;
}
public synchronized void put(char x) {
while(n >= MAX) {
wait();
}
buffer.append(x); n++;
notify();
}
public synchronized char get() {
while (n <= 0){
wait();
}
notify(); n--;
return buffer.dequeue();
}
}