LinkedBlockingQueue原理是什么

本篇內(nèi)容主要講解“LinkedBlockingQueue原理是什么”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“LinkedBlockingQueue原理是什么”吧!

目前創(chuàng)新互聯(lián)公司已為數(shù)千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、成都網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計、上林網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

LinkedBlockingQueue

構(gòu)成鏈表的節(jié)點表示
static class Node < E > {
    E item;
    Node < E > next;
    Node(E x) {
        item = x;
    }
}


鏈表屬性
private final int capacity;

private final AtomicInteger count = new AtomicInteger();

transient Node < E > head;

private transient Node < E > last;
private final ReentrantLock takeLock = new ReentrantLock();
private final ReentrantLock putLock = new ReentrantLock();
private final Condition notEmpty = takeLock.newCondition();

private final Condition notFull = putLock.newCondition();
使用的方法有
private void signalNotEmpty();
private void signalNotFull();
private void enqueue(Node < E > node);
private E dequeue();
雙鎖

// 把固定的加鎖順序封裝在方法內(nèi),確保所有的對兩把鎖加鎖的順序都是一致的。
void fullyLock() {
    putLock.lock();
    takeLock.lock();
}

// 把固定的釋放鎖順序封裝在方法內(nèi),確保所有的對兩把鎖的釋放順序都是一致的。
void fullyUnlock() {
    takeLock.unlock();
    putLock.unlock();
}


構(gòu)造方法
public LinkedBlockingQueue(int capacity) {
    if (capacity <= 0) throw new IllegalArgumentException();
    this.capacity = capacity;
    last = head = new Node < E > (null);
}
public LinkedBlockingQueue(Collection < ? extends E > c)

public int size()
public int remainingCapacity()

public void put(E e) throws InterruptedException
public boolean offer(E e, long timeout, TimeUnit unit)

public boolean offer(E e)

public E take() throws InterruptedException
public E poll(long timeout, TimeUnit unit) throws InterruptedException
public E poll()
/**從頭拿**/
public E peek()


public boolean remove(Object o)
public boolean contains(Object o)
public Object[] toArray()
public < T > T[] toArray(T[] a)
    ......

到此,相信大家對“LinkedBlockingQueue原理是什么”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

名稱欄目:LinkedBlockingQueue原理是什么
本文來源:http://muchs.cn/article22/ipjgjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、網(wǎng)站排名手機網(wǎng)站建設(shè)定制網(wǎng)站、品牌網(wǎng)站制作、網(wǎng)站策劃

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)