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

后端 未结 4 571
隐瞒了意图╮
隐瞒了意图╮ 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:35

    2 locks are used in LBQ to restrict access to head and lock concurrently. The head lock disallows two elements from being removed concurrently and tail lock disallows two elements from being concurrently added to the queue. the two lock together prevent races.

提交回复
热议问题