ArrayBlockingQueue should meet the requirements of LZ, but you still need to judge based on the return value of the offer.
The size of ConcurrentLinkedQueue is not a constant time operation, so it is slow. LinkedBlockingQueue is implemented using a linked list, and it is not specifically designed for fixed-size queues, so it is also slow.
If it is more complicated, especially if the reading thread is much larger than the writing thread, use LMAX RingBuffer.
LinkedQueueSlowness is because every time you insert or delete an element, there are four pointer operations. If you have a fixed size, using array is the best way.
ArrayBlockingQueue should meet the requirements of LZ, but you still need to judge based on the return value of the offer.
The size of ConcurrentLinkedQueue is not a constant time operation, so it is slow. LinkedBlockingQueue is implemented using a linked list, and it is not specifically designed for fixed-size queues, so it is also slow.
Easy,
ArrayBlockingQueue
.If it is more complicated, especially if the reading thread is much larger than the writing thread, use LMAX
RingBuffer
.LinkedQueue
Slowness is because every time you insert or delete an element, there are four pointer operations. If you have a fixed size, using array is the best way.