/** The queued items */final Object[] items;/** items index for next take, poll, peek or remove */int takeIndex;/** items index for next put, offer, or add */int putIndex;/** Number of elements in the queue */int count;/*
* Concurrency control uses the classic two-condition algorithm
* found in any textbook.
*//** 访问数据时的锁 */final ReentrantLock lock;/** Condition for waiting takes */// 正在等待拿数据的条件队列privatefinal Condition notEmpty;/** Condition for waiting puts */// 正在等待添加数据的条件队列privatefinal Condition notFull;// 使用迭代器时的共享状态transient Itrs itrs = null;// 索引-1 后的下标finalintdec(int i){return((i ==0)? items.length : i)-1;}// 返回某个位置的元素final E itemAt(int i){return(E) items[i];}
ArrayBlockingQueue基于数组实现了阻塞队列必须指定空间大小,可以设置生产、消费线程等待顺序的公平性、默认非公平使用公平获取资源将会降低吞吐量,但是可以避免饥饿基本属性&方法:/** The queued items */final Object[] items;/** items index for next take, poll, peek or remove */int takeIndex;/** items index for next put, of