1 17 18 package org.apache.tomcat.util.collections; 19 20 import java.util.Vector ; 21 22 29 public class Queue { 30 private Vector vector = new Vector (); 31 private boolean stopWaiting=false; 32 private boolean waiting=false; 33 34 40 public synchronized void put(Object object) { 41 vector.addElement(object); 42 notify(); 43 } 44 45 47 public synchronized void stop() { 48 stopWaiting=true; 49 if( waiting ) notify(); 51 } 52 53 57 public synchronized Object pull() { 58 while (isEmpty()) { 59 try { 60 waiting=true; 61 wait(); 62 } catch (InterruptedException ex) { 63 } 64 waiting=false; 65 if( stopWaiting ) return null; 66 } 67 return get(); 68 } 69 70 74 public synchronized Object get() { 75 Object object = peek(); 76 if (object != null) 77 vector.removeElementAt(0); 78 return object; 79 } 80 81 84 public Object peek() { 85 if (isEmpty()) 86 return null; 87 return vector.elementAt(0); 88 } 89 90 93 public boolean isEmpty() { 94 return vector.isEmpty(); 95 } 96 97 100 public int size() { 101 return vector.size(); 102 } 103 } 104 | Popular Tags |