1 2 23 24 25 public class ProducerConsumer { 26 27 30 public static ProducerConsumer pc = new ProducerConsumer(); 31 32 35 private java.util.Vector queue = new java.util.Vector (); 36 37 41 synchronized public void addToken(Token token) { 42 queue.addElement(token); 43 notify(); 44 } 45 46 51 synchronized public Token getToken() { 52 if (queue.size() == 0) { 53 try { 54 wait(); 55 } catch (InterruptedException willNotHappen) { 56 throw new Error (); 57 } 58 } 59 Token retval = (Token)(queue.elementAt(0)); 60 queue.removeElementAt(0); 61 return retval; 62 } 63 64 } 65 | Popular Tags |