0

I know there have been questions and discussions about this(ArrayBlockingQueue uses a single lock for insertion and removal but LinkedBlockingQueue uses 2 separate locks) and (What is the reason to implement ArrayBlockingQueue with one lock on tail and head?), but I still don't understand it.

There is an accepted answer in the link given above:

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.

I don't quite understand, can someone explain it to me?

Then I tried to transform ABQ with two locks and ran throughput tests following the code in book Java Concurrency in practice, and it did prove that the double-locked version of ABQ has better throughput.

All code (including ABQ using double lock implementatio and test code from book Java Concurrency in practice) can be seen here: https://pastebin.com/QpW9dsVc

Is there a bug in the ABQ code that uses the double lock implementation, If not, why not use double locks.

2
  • The accepted answer doesn't explain anything. The answer by @Gray seems more like it. Commented Oct 17, 2021 at 6:14
  • But it still seems possible to use double locks @user207421 Commented Oct 17, 2021 at 6:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.