LinkedBlockingQueue和ConcurrentLinkedQueue有什么区别? [英] What's the different between LinkedBlockingQueue and ConcurrentLinkedQueue?
问题描述
我已阅读过博客,但我不确定他的结论是否正确:
http://www.javacodegeeks.com/2010/09/java-best-practices-queue- battle-and.html#ixzz1seaiSLwp
他说:从提供的性能结果可以看出,LinkedBlockingQueue实现了最佳组合
我不知道,如果我没有这样做,那么为什么LinkedBlockingQueue比无锁队列(ConcurrentLinkedQueue)更快?
谢谢!
ConcurrentLinkedQueue不是阻止队列。它不实现BlockingQueue接口,因此不提供阻塞方法put()和take()。这些方法对于生产者/消费者设置是必要的,因为您需要安排消费者在没有消费的情况下阻止,并且当消费者不能快速消费时,阻止消费者。
I've read the blog, but i'm not sure whether his conclusion is correct :
http://www.javacodegeeks.com/2010/09/java-best-practices-queue-battle-and.html#ixzz1seaiSLwp
He said : As you can see from the provided performance results LinkedBlockingQueue achieved the best combined (adding and removing elements) performance results and should be your number one candidate for implementing producer – consumer schenarios.
I wonder that, doen't it faster if i don't use lock in my code ?
So why the LinkedBlockingQueue is faster than the lock-free Queue(ConcurrentLinkedQueue) ?
Thanks !
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.
这篇关于LinkedBlockingQueue和ConcurrentLinkedQueue有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!