ConcurrentLinkedDeque vs ArrayDeque

2.9k Views Asked by At

I know the basic difference between two of them that ConcurrentLinkedDeque can be use in multithreaded application.

Can any one give me practical example how it would affect the performance of application if wrongly used, in which scenario i should go with ConcurrentLinkedDeque and when to use ArrayDeque.

1

There are 1 best solutions below

3
On

Use ConcurrentLinkedDeque if you need synchronized access to your queue from multiple threads, ArrayDeque if not.

Period.

The consequence of using the wrong one is that if you attempt to access an ArrayDeque in a multi-thread setting you will corrupt your queue.

Period.

That is your only performance consideration. All others are moot.

Unless...

You ran your application through a profiler and discovered most of its time is spent inside of ConcurrentLinkedDeque.size(). Then switch to ArrayDeque wrapped in synchronized blocks.

End of lecture ;)