What is the Difference between ArrayBlockingQueue and LinkedBlockingQueue

前端 未结 4 1286
长发绾君心
长发绾君心 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:44

    ArrayBlockingQueue is backed by an array that size will never change after creation. Setting the capacity to Integer.MAX_VALUE would create a big array with high costs in space. ArrayBlockingQueue is always bounded.

    LinkedBlockingQueue creates nodes dynamically until the capacity is reached. This is by default Integer.MAX_VALUE. Using such a big capacity has no extra costs in space. LinkedBlockingQueue is optionally bounded.

提交回复
热议问题