What is the Difference between ArrayBlockingQueue and LinkedBlockingQueue

前端 未结 4 1370
长发绾君心
长发绾君心 2021-01-30 13:22
  1. What scenarios is it better to use an ArrayBlockingQueue and when is it better to use a LinkedBlockingQueue?
  2. If LinkedBlockingQueue default capacity is equal to M
4条回答
  •  梦谈多话
    2021-01-30 13:55

    ArrayBlockingQueue and LinkedBlockingQueue are common implementations of the BlockingQueue interface.

    ArrayBlockingQueue is backed by array and Queue impose orders as FIFO. head of the queue is the oldest element in terms of time and tail of the queue is youngest element. ArrayBlockingQueue is also fixed size bounded buffer on the other hand LinkedBlockingQueue is an optionally bounded queue built on top of Linked nodes.

    The optional capacity bound constructor argument serves as a way to prevent excessive queue expansion because if capacity is unspecified, than it is equal to Integer.MAX_VALUE.

    Read more From here.

    Benchmark: http://www.javacodegeeks.com/2010/09/java-best-practices-queue-battle-and.html

提交回复
热议问题