1 package org.sapia.ubik.util; 2 3 import java.util.LinkedList ; 4 5 16 public class Queue { 17 protected LinkedList _items = new LinkedList (); 18 private boolean _added; 19 20 23 public Queue(){ 24 } 25 26 31 public synchronized void add(Object o, boolean notifyAll){ 32 33 _items.add(o); 34 _added = true; 35 if(notifyAll){ 36 notifyAll(); 37 } 38 else{ 39 notify(); 40 } 41 } 42 43 49 public synchronized Object remove() throws InterruptedException { 50 while(_items.size() == 0){ 51 wait(); 52 } 53 _added = false; 54 return _items.removeFirst(); 55 } 56 57 60 public int size(){ 61 return _items.size(); 62 } 63 64 67 public boolean wasItemAdded(){ 68 return _added; 69 } 70 71 protected void resetAddedFlag(){ 72 _added = false; 73 } 74 } 75 | Popular Tags |