5

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 !

2
  • 3
    Forget random blogs: have you considered reading the Javadoc? DIdn't the words 'bounded', 'unbounded', and 'blocking' convey anything at all? Commented Sep 5, 2012 at 6:49
  • Related: stackoverflow.com/q/1426754/931379 Commented Sep 17, 2013 at 22:14

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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();

Comments

-3

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

2 Comments

LinkedBlockingDeque and LinkedBlockingQueue are two different classes.
I don't think LInkedBlockingQueue is a deque, and I don't think ConcurrentBlockingQueue is a class in the Java runtime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.