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

📄 baseboundedbuffer.java

📁 java concurrency in practice 源码. JAVA并发设计
💻 JAVA
字号:
package net.jcip.examples;import net.jcip.annotations.*;/** * BaseBoundedBuffer * <p/> * Base class for bounded buffer implementations * * @author Brian Goetz and Tim Peierls */@ThreadSafepublic abstract class BaseBoundedBuffer <V> {    @GuardedBy("this") private final V[] buf;    @GuardedBy("this") private int tail;    @GuardedBy("this") private int head;    @GuardedBy("this") private int count;    protected BaseBoundedBuffer(int capacity) {        this.buf = (V[]) new Object[capacity];    }    protected synchronized final void doPut(V v) {        buf[tail] = v;        if (++tail == buf.length)            tail = 0;        ++count;    }    protected synchronized final V doTake() {        V v = buf[head];        buf[head] = null;        if (++head == buf.length)            head = 0;        --count;        return v;    }    public synchronized final boolean isFull() {        return count == buf.length;    }    public synchronized final boolean isEmpty() {        return count == 0;    }}

⌨️ 快捷键说明

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