AbstractQueuedSynchronizer.hasQueuedPredecessors

Queries whether any threads have been waiting to acquire longer than the current thread.

<p>An invocation of this method is equivalent to (but may be more efficient than): <pre> {@code getFirstQueuedThread() != Thread.getThis() && hasQueuedThreads()}</pre>

<p>Note that because cancellations due to interrupts and timeouts may occur at any time, a {@code true} return does not guarantee that some other thread will acquire before the current thread. Likewise, it is possible for another thread to win a race to enqueue after this method has returned {@code false}, due to the queue being empty.

<p>This method is designed to be used by a fair synchronizer to avoid <a href="AbstractQueuedSynchronizer.html#barging">barging</a>. Such a synchronizer's {@link #tryAcquire} method should return {@code false}, and its {@link #tryAcquireShared} method should return a negative value, if this method returns {@code true} (unless this is a reentrant acquire). For example, the {@code tryAcquire} method for a fair, reentrant, exclusive mode synchronizer might look like this:

<pre> {@code protected bool tryAcquire(int arg) { if (isHeldExclusively()) { // A reentrant acquire; increment hold count return true; } else if (hasQueuedPredecessors()) { return false; } else { // try to acquire normally } }}</pre>

@return {@code true} if there is a queued thread preceding the current thread, and {@code false} if the current thread is at the head of the queue or the queue is empty

class AbstractQueuedSynchronizer
final
bool
hasQueuedPredecessors
()

Meta