LinkedBlockingQueue

    /**
               
     **/
    public void put(E e) throws InterruptedException {
        if (e == null) throw new NullPointerException();
        int c = -1;
        final ReentrantLock putLock = this.putLock;
        final AtomicInteger count = this.count;
        putLock.lockInterruptibly();
        try {
            try {
                //     ,         
                while (count.get() == capacity)
                    notFull.await();
            } catch (InterruptedException ie) {
                notFull.signal();
                throw ie;
            }
            insert(e);
            c = count.getAndIncrement();
            //    ,           
            if (c + 1 < capacity)
                notFull.signal();
        } finally {
            putLock.unlock();
        }
        //     ,          ,          ,        
        if (c == 0)
            signalNotEmpty();
    }

좋은 웹페이지 즐겨찾기