FileDocCategorySizeDatePackage
Queue.javaAPI DocApache Tomcat 6.0.142725Fri Jul 20 04:20:36 BST 2007org.apache.tomcat.util.collections

Queue

public class Queue extends Object
A simple FIFO queue class which causes the calling thread to wait if the queue is empty and notifies threads that are waiting when it is not empty.
author
Anil V (akv@eng.sun.com)

Fields Summary
private Vector
vector
private boolean
stopWaiting
private boolean
waiting
Constructors Summary
Methods Summary
public synchronized java.lang.Objectget()
Get the first object out of the queue. Return null if the queue is empty.

	Object object = peek();
	if (object != null)
	    vector.removeElementAt(0);
	return object;
    
public booleanisEmpty()
Is the queue empty?

	return vector.isEmpty();
    
public java.lang.Objectpeek()
Peek to see if something is available.

	if (isEmpty())
	    return null;
	return vector.elementAt(0);
    
public synchronized java.lang.Objectpull()
Pull the first object out of the queue. Wait if the queue is empty.

	while (isEmpty()) {
	    try {
		waiting=true;
		wait();
	    } catch (InterruptedException ex) {
	    }
	    waiting=false;
	    if( stopWaiting ) return null;
	}
	return get();
    
public synchronized voidput(java.lang.Object object)
Put the object into the queue.

param
object the object to be appended to the queue.

    
             			       				      
         
	vector.addElement(object);
	notify();
    
public intsize()
How many elements are there in this queue?

	return vector.size();
    
public synchronized voidstop()
Break the pull(), allowing the calling thread to exit

	stopWaiting=true;
	// just a hack to stop waiting 
	if( waiting ) notify();