The LinkedBlockingQueue class implements the BlockingQueue interface. Read the BlockingQueue text for more information about the interface.
The LinkedBlockingQueue keeps the elements internally in a linked structure (linked nodes). This linked structure can optionally have an upper bound if desired. If no upper bound is specified, Integer.MAX_VALUE is used as the upper bound.
The LinkedBlockingQueue stores the elements internally in FIFO (First In, First Out) order. The head of the queue is the element which has been in queue the longest time, and the tail of the queue is the element which has been in the queue the shortest time.
Here is how to instantiate and use a LinkedBlockingQueue:
BlockingQueue<String> unbounded = new LinkedBlockingQueue<String>();
BlockingQueue<String> bounded = new LinkedBlockingQueue<String>(1024);
bounded.put("Value");
String value = bounded.take();
本文介绍了Java并发包中LinkedBlockingQueue的实现原理与使用方法。它实现了阻塞队列接口,内部采用链表结构存储元素,并可选地设置容量上限,默认为Integer.MAX_VALUE。元素按照先进先出(FIFO)原则存储,提供了put和take方法来实现线程间的同步。
1113

被折叠的 条评论
为什么被折叠?



