Parallel Programming WS 2014/2015 - File Buffer.java
public class Buffer {
private Queue buf;
public Buffer(int n) {
buf = new Queue(n);
}
synchronized public void put(int elem) {
while (buf.isFull()) {
try {
wait();
} catch (InterruptedException ie) {/* ok to ignore */}
}
buf.enqueue(elem);
System.out.println("put " + elem + " (" + buf.getElementCount() + " elems in q)");
notifyAll();
}
synchronized public int get() {
while (buf.isEmpty()) {
try {
wait();
} catch (InterruptedException ie) {/* ok to ignore */}
}
int elem = buf.dequeue();
System.out.println("get " + elem + " (" + buf.getElementCount() + " elems in q)");
notifyAll();
return elem;
}
}
Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 20.11.2014


