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

📄 bufferimpl.java

📁 演示win32的socket 通讯 八皇后的改进算法 并发Concurrency的JAVA实现 applet演示鼠标的点击时间和显示图象 手机J2ME的多线程演示
💻 JAVA
字号:
package concurrency.buffer;

/*********************BUFFER*****************************/

public class BufferImpl implements Buffer {

    protected Object[] buf;
    protected int in = 0;
    protected int out= 0;
    protected int count= 0;
    protected int size;

    public BufferImpl(int size) {
        this.size = size;
        buf = new Object[size];
    }

    public synchronized void put(Object o) throws InterruptedException {
        while (count==size) wait();
        buf[in] = o;
        ++count;
        in=(in+1) % size;
        notify();
    }

    public synchronized Object get() throws InterruptedException {
        while (count==0) wait();
        Object o =buf[out];
        buf[out]=null;
        --count;
        out=(out+1) % size;
        notify();
        return (o);
    }
}

⌨️ 快捷键说明

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