⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boundedbuffer.java

📁 java concurrency in practice 源码. JAVA并发设计
💻 JAVA
字号:
package net.jcip.examples;import net.jcip.annotations.*;/** * BoundedBuffer * <p/> * Bounded buffer using condition queues * * @author Brian Goetz and Tim Peierls */@ThreadSafe        public class BoundedBuffer <V> extends BaseBoundedBuffer<V> {    // CONDITION PREDICATE: not-full (!isFull())    // CONDITION PREDICATE: not-empty (!isEmpty())    public BoundedBuffer() {        this(100);    }    public BoundedBuffer(int size) {        super(size);    }    // BLOCKS-UNTIL: not-full    public synchronized void put(V v) throws InterruptedException {        while (isFull())            wait();        doPut(v);        notifyAll();    }    // BLOCKS-UNTIL: not-empty    public synchronized V take() throws InterruptedException {        while (isEmpty())            wait();        V v = doTake();        notifyAll();        return v;    }    // BLOCKS-UNTIL: not-full    // Alternate form of put() using conditional notification    public synchronized void alternatePut(V v) throws InterruptedException {        while (isFull())            wait();        boolean wasEmpty = isEmpty();        doPut(v);        if (wasEmpty)            notifyAll();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -