RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
LinkedBlockingQueue原理是什么

本篇内容主要讲解“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原理是什么
网站URL:http://scyingshan.cn/article/ipjgjc.html