ArrayBlockingQueue是一个用数组实现的有界阻塞队列。此队列按照先进先出(FIFO)的原则对元素进行排序,默认是非公平锁。
    使用通知模式实现阻塞队列,ArrayBlockingQueue使用了Condition来实现,阻塞是用的LockSupport.park(this)来实现。

    1. //放
    2. public void put(E e) throws InterruptedException {
    3. checkNotNull(e);
    4. final ReentrantLock lock = this.lock;
    5. lock.lockInterruptibly();
    6. try {
    7. while (count == items.length)
    8. notFull.await();
    9. enqueue(e);
    10. } finally {
    11. lock.unlock();
    12. }
    13. }
    1. //取
    2. public E take() throws InterruptedException {
    3. final ReentrantLock lock = this.lock;
    4. lock.lockInterruptibly();
    5. try {
    6. while (count == 0)
    7. notEmpty.await();
    8. return dequeue();
    9. } finally {
    10. lock.unlock();
    11. }
    12. }