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 (Message msg)
{ msgQueue.enqueue (msg); notify(); }
public synchronized Message receive ()
{ while (msgQueue.empty())
try { wait(); } catch (InterruptedException e) {}
Message result = (Message) msgQueue.front();
msgQueue.dequeue();
return result;
}
public synchronized boolean empty ()
{ return msgQueue.empty (); }
}
Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 02.02.2015


