Parallel Programming WS 2014/2015 - File Channel.java
public class Channel { // Implementation of a Channel using a Queue of messages
private Queue msgQueue;
public Channel() {
msgQueue = new Queue();
}
public synchronized void send(Object msg) {
msgQueue.enqueue(msg);
notifyAll();
}
public synchronized Object receive() {
while (msgQueue.empty()) {
try {
wait();
} catch (InterruptedException e) {}
}
Object result = msgQueue.front();
msgQueue.dequeue();
return result;
}
public synchronized boolean empty() {
return msgQueue.empty();
}
}
Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 19.01.2015


