Two sentences in the JavaDoc for AbstractQueuedSynchronizer are in my opinion unclear/misleading, and therefore I would like to clarify such issues.
The first sentence states:
Even though this class is based on an internal FIFO queue, it does not automatically enforce FIFO acquisition policies.
What is exactly meant with the sentence above? Looking up the source code for the class itself (which has several methods marked as final
), I am currently seeing only one case where FIFO could not be enforced, that is when tryAcquire
returns true
. When a tryAcquire
returns false
and the caller thread must be parked, I can not find any way to bypass FIFO. In case my assumption is correct, should not the documentation be made more clear?
The second sentence states:
Because checks in acquire are invoked before enqueuing, a newly acquiring thread may barge ahead of others that are blocked and queued. However, you can, if desired, define tryAcquire and/or tryAcquireShared to disable barging by internally invoking one or more of the inspection methods, thereby providing a fair FIFO acquisition order.
What is exactly meant here with barging? Is the documentation talking again about the case where the acquiring thread is not parked?
My currently understanding is as following: as long as the acquiring thread is not parked, strategies other than FIFO are possible. In case the acquiring thread must be parked, FIFO will be used.
Do you agree with my statements or am I getting something wrong? Does it make sense to open a BUG for Oracle to fix it?