深入研究Java阻塞队列实现

阻塞队列是一个非常常见的数据结构,比如在线程池中用阻塞队列存放任务,下面我们将围绕阻塞队列的实现对其源码进行深度剖析,主要讲解ArrayBlockingQueue、PriorityBlockingQueue、SynchronousQueue和LinkedBlockingQueue四大阻塞队列的实现。

LinkedBlockingQueue

  • 双锁队列算法的变体

优化

1
2
3
4
5
6
7
8
9
10
11
private E dequeue() {
// assert takeLock.isHeldByCurrentThread();
// assert head.item == null;
Node<E> h = head;
Node<E> first = h.next;
h.next = h; // help GC
head = first;
E x = first.item;
first.item = null;
return x;
}

基本接口

  • offer()方法和put()方法的区别?
  • 线程池如何关闭空闲线程的?

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×