When to prefer LinkedBlockingQueue over ArrayBlockingQueue?

前端 未结 2 869
遇见更好的自我
遇见更好的自我 2021-01-30 08:23

When to prefer LinkedBlockingQueue over ArrayBlockingQueue?

Which data structure to use among LinkedBlockingQueue and ArrayB

2条回答
  •  孤城傲影
    2021-01-30 08:58

    From the JavaDoc for ArrayBlockingQueue

    A bounded blocking queue backed by an array.

    Emphasis mine

    From the JavaDoc for LinkedBlockingQueue:

    An optionally-bounded blocking queue based on linked nodes.

    Emphasis mine

    So if you need a bounded queue you can use either, if you need an unbounded queue you must use LinkedBlockingQueue.

    For a bounded queue, then you would need to benchmark to work out which is better.

提交回复
热议问题