
java并发编程系列
zjuwzp
这个作者很懒,什么都没留下…
展开
-
LinkedBlockingQueue的构造过程
LinkedBlockingQueue的构造LinkedBlockingQueue<String> linkedBlockingQueue = new LinkedBlockingQueue<String>(20);构造函数public LinkedBlockingQueue(int capacity) { if (capacity <= 0) thr...原创 2020-01-04 22:32:55 · 477 阅读 · 0 评论 -
ConcurrentLinkedQueue总结
offer的多线程并发安全if (p.casNext(null, newNode)) {上面这行代码通过CAS操作入队,同一时间只有一个线程可以成功。其他线程入队失败,然后死循环,不断尝试让指针往后挪动到最后一个尾部节点,再次尝试用CAS将自己入队,加入队尾。...原创 2020-01-04 19:51:56 · 576 阅读 · 0 评论 -
ConcurrentLinkedQueue多线程安全的并发删除队列元素
1、remove方法public boolean remove(Object o) { if (o != null) { Node<E> next, pred = null; for (Node<E> p = first(); p != null; pred = p, p = next) { boole...原创 2020-01-04 10:55:26 · 2577 阅读 · 0 评论 -
ConcurrentLinkedQueue的peek
1、peek函数public E peek() { restartFromHead: for (;;) { for (Node<E> h = head, p = h, q;;) { E item = p.item; if (item != null || (q = p.next) == null) { ...原创 2020-01-04 09:53:31 · 815 阅读 · 0 评论 -
ConcurrentLinkedQueue出队
出队函数public E poll() { restartFromHead: for (;;) { for (Node<E> h = head, p = h, q;;) { E item = p.item; if (item != null && p.casItem(item, null...原创 2020-01-02 07:55:41 · 515 阅读 · 0 评论 -
ConcurrentLinkedQueue的offer方法
1、构造函数public ConcurrentLinkedQueue() { head = tail = new Node<E>(null);}点击new Node(null)进入如下代码Node(E item) { UNSAFE.putObject(this, itemOffset, item);}这里的itemOffset是item这个属性相对于No...原创 2020-01-01 09:42:21 · 3503 阅读 · 0 评论 -
CopyOnWriteArrayList
空参构造函数public CopyOnWriteArrayList() { setArray(new Object[0]);}构造一个空数组,调用setArray将其赋值给成员变量array。final void setArray(Object[] a) { array = a;}成员变量array用volatile修饰。private transient vol...原创 2019-12-31 22:35:29 · 210 阅读 · 0 评论