有没有Blocking Bounded Queue 用Pthread实现的Sample Code?# JobHunting - 待字闺中k*t2013-01-26 08:011 楼要用两个conditional variable吗?谢了。
c*r2013-01-26 08:012 楼Pthread 没有,有一个thread的public class BlockingQueue {private List queue = new LinkedList();private int limit = 10;public BlockingQueue(int limit){this.limit = limit;}public synchronized void enqueue(Object item) throws InterruptedException{while(this.queue.size() == this.limit){wait();}if(this.queue.isEmpty()){notifyAll();}this.queue.add(item);}public synchronized Object dequeue() throws InterruptedException {while(this.queue.isEmpty()){wailt();}if(this.queue.size() == this.limit){notifyAll();}return this.queue.remove(0);}}