What's the different between LinkedBlockingQueue and ConcurrentLinkedQueue?

限于喜欢 提交于 2019-12-03 16:16:05

ConcurrentLinkedQueue is not a blocking queue. It does not implement the BlockingQueue interface, and therefore does not provide the blocking methods put() and take(). These methods are necessary for a producer/consumer setup, because you need to arrange for the consumer to block while there is nothing to consume, and for the producer to block when the consumers don't consume quickly enough.

This benchmark is weird : using the concurrent queue as a blocking queue make no sense or am I missing something. This code is not going to save the planet I guess :

while(result == null)
   result = concurrentLinkedQueue.poll();

and is of course less efficient than :

linkedBlockingQueue.take();

LinkedBlockingQueue is a Deque and ConcurrentBlockingQueue is not. Check Javadoc for more details

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!