< prev index next >

src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java

Print this page
8234131: Miscellaneous changes imported from jsr166 CVS 2020-06
Reviewed-by: martin


 120  * </ul>
 121  *
 122  * Each of these methods by default throws {@link
 123  * UnsupportedOperationException}.  Implementations of these methods
 124  * must be internally thread-safe, and should in general be short and
 125  * not block. Defining these methods is the <em>only</em> supported
 126  * means of using this class. All other methods are declared
 127  * {@code final} because they cannot be independently varied.
 128  *
 129  * <p>You may also find the inherited methods from {@link
 130  * AbstractOwnableSynchronizer} useful to keep track of the thread
 131  * owning an exclusive synchronizer.  You are encouraged to use them
 132  * -- this enables monitoring and diagnostic tools to assist users in
 133  * determining which threads hold locks.
 134  *
 135  * <p>Even though this class is based on an internal FIFO queue, it
 136  * does not automatically enforce FIFO acquisition policies.  The core
 137  * of exclusive synchronization takes the form:
 138  *
 139  * <pre>
 140  * Acquire:
 141  *     while (!tryAcquire(arg)) {
 142  *        <em>enqueue thread if it is not already queued</em>;
 143  *        <em>possibly block current thread</em>;
 144  *     }
 145  *
 146  * Release:
 147  *     if (tryRelease(arg))
 148  *        <em>unblock the first queued thread</em>;
 149  * </pre>
 150  *
 151  * (Shared mode is similar but may involve cascading signals.)
 152  *
 153  * <p id="barging">Because checks in acquire are invoked before
 154  * enqueuing, a newly acquiring thread may <em>barge</em> ahead of
 155  * others that are blocked and queued.  However, you can, if desired,
 156  * define {@code tryAcquire} and/or {@code tryAcquireShared} to
 157  * disable barging by internally invoking one or more of the inspection
 158  * methods, thereby providing a <em>fair</em> FIFO acquisition order.
 159  * In particular, most fair synchronizers can define {@code tryAcquire}
 160  * to return {@code false} if {@link #hasQueuedPredecessors} (a method
 161  * specifically designed to be used by fair synchronizers) returns
 162  * {@code true}.  Other variations are possible.
 163  *
 164  * <p>Throughput and scalability are generally highest for the
 165  * default barging (also known as <em>greedy</em>,
 166  * <em>renouncement</em>, and <em>convoy-avoidance</em>) strategy.




 120  * </ul>
 121  *
 122  * Each of these methods by default throws {@link
 123  * UnsupportedOperationException}.  Implementations of these methods
 124  * must be internally thread-safe, and should in general be short and
 125  * not block. Defining these methods is the <em>only</em> supported
 126  * means of using this class. All other methods are declared
 127  * {@code final} because they cannot be independently varied.
 128  *
 129  * <p>You may also find the inherited methods from {@link
 130  * AbstractOwnableSynchronizer} useful to keep track of the thread
 131  * owning an exclusive synchronizer.  You are encouraged to use them
 132  * -- this enables monitoring and diagnostic tools to assist users in
 133  * determining which threads hold locks.
 134  *
 135  * <p>Even though this class is based on an internal FIFO queue, it
 136  * does not automatically enforce FIFO acquisition policies.  The core
 137  * of exclusive synchronization takes the form:
 138  *
 139  * <pre>
 140  * <em>Acquire:</em>
 141  *     while (!tryAcquire(arg)) {
 142  *        <em>enqueue thread if it is not already queued</em>;
 143  *        <em>possibly block current thread</em>;
 144  *     }
 145  *
 146  * <em>Release:</em>
 147  *     if (tryRelease(arg))
 148  *        <em>unblock the first queued thread</em>;
 149  * </pre>
 150  *
 151  * (Shared mode is similar but may involve cascading signals.)
 152  *
 153  * <p id="barging">Because checks in acquire are invoked before
 154  * enqueuing, a newly acquiring thread may <em>barge</em> ahead of
 155  * others that are blocked and queued.  However, you can, if desired,
 156  * define {@code tryAcquire} and/or {@code tryAcquireShared} to
 157  * disable barging by internally invoking one or more of the inspection
 158  * methods, thereby providing a <em>fair</em> FIFO acquisition order.
 159  * In particular, most fair synchronizers can define {@code tryAcquire}
 160  * to return {@code false} if {@link #hasQueuedPredecessors} (a method
 161  * specifically designed to be used by fair synchronizers) returns
 162  * {@code true}.  Other variations are possible.
 163  *
 164  * <p>Throughput and scalability are generally highest for the
 165  * default barging (also known as <em>greedy</em>,
 166  * <em>renouncement</em>, and <em>convoy-avoidance</em>) strategy.


< prev index next >