• 有界缓存实现基类


    public abstract class BaseBoundedBuffer<V>
    {
        private final V[] buf;
       
        private int tail;
       
        private int head;
       
        private int count;
       
        @SuppressWarnings("unchecked")
        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;
        }
    }

  • 相关阅读:
    JavaScripts广告轮播图以及定时弹出和定时隐藏广告
    JavaScript正则表达
    表单常用标签 和 属性
    html框架集
    Hbuilder 快捷键
    css 图片
    html input accept类型
    db2 sql
    js 数组排序
    html input size maxlength
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3293992.html
Copyright © 2020-2023  润新知