本篇內容主要講解“LinkedBlockingQueue原理是什么”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“LinkedBlockingQueue原理是什么”吧!
目前創新互聯公司已為數千家的企業提供了網站建設、域名、虛擬空間、成都網站托管、企業網站設計、上林網站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協力一起成長,共同發展。
LinkedBlockingQueue
構成鏈表的節點表示
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();
雙鎖
// 把固定的加鎖順序封裝在方法內,確保所有的對兩把鎖加鎖的順序都是一致的。 void fullyLock() { putLock.lock(); takeLock.lock(); } // 把固定的釋放鎖順序封裝在方法內,確保所有的對兩把鎖的釋放順序都是一致的。 void fullyUnlock() { takeLock.unlock(); putLock.unlock(); }
構造方法
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原理是什么”有了更深的了解,不妨來實際操作一番吧!這里是創新互聯網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
名稱欄目:LinkedBlockingQueue原理是什么
本文來源:http://www.2m8n56k.cn/article22/ipjgjc.html
成都網站建設公司_創新互聯,為您提供網站營銷、網站排名、手機網站建設、定制網站、品牌網站制作、網站策劃
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:[email protected]。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯