FileDocCategorySizeDatePackage
WaitingQueue.javaAPI DocExample859Wed Apr 20 15:12:34 BST 2005None

WaitingQueue

public class WaitingQueue extends Object
A queue. One thread calls push() to put an object on the queue. Another calls pop() to get an object off the queue. If there is no data, pop() waits until there is some, using wait()/notify(). wait() and notify() must be used within a synchronized method or block. In Java 5.0, use a java.util.concurrent.BlockingQueue instead.

Fields Summary
LinkedList
q
Constructors Summary
Methods Summary
public synchronized Epop()

        while(q.size() == 0) {
            try { this.wait(); }
            catch (InterruptedException ignore) {}
        }
        return q.remove(0);
    
public synchronized voidpush(E o)

  // Where objects are stored
         
        q.add(o);         // Append the object to the end of the list
        this.notifyAll(); // Tell waiting threads that data is ready