ArrayBlockingQueue uses a single lock for insertion and removal but LinkedBlockingQueue uses 2 separate locks

后端 未结 4 563
隐瞒了意图╮
隐瞒了意图╮ 2020-12-09 06:22

I was going through the source code of ArrayBlockingQueue and LinkedBlockingQueue. LinkedBlockingQueue has a putLock and a takeLock for insertion and removal respectively bu

4条回答
  •  死守一世寂寞
    2020-12-09 06:36

    ArrayBlockingQueue has to avoid overwriting entries so that it needs to know where the start and the end is. A LinkedBlockQueue doesn't need to know this as it lets the GC worry about cleaning up Nodes in the queue.

提交回复
热议问题