Top Description Inners Fields Constructors Methods
java.util.concurrent.locks

public abstract Class AbstractQueuedLongSynchronizer

extends AbstractOwnableSynchronizer
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.util.ArrayList, .Collection, .Date, java.util.concurrent.TimeUnit, .ForkJoinPool, .RejectedExecutionException, jdk.internal.misc.Unsafe

A version of AbstractQueuedSynchronizer in which synchronization state is maintained as a long. This class has exactly the same structure, properties, and methods as AbstractQueuedSynchronizer with the exception that all state-related parameters and results are defined as long rather than int. This class may be useful when creating synchronizers such as multilevel locks and barriers that require 64 bits of state.

See AbstractQueuedSynchronizer for usage notes and examples.

Author
Doug Lea
Since
1.6

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
public class
AbstractQueuedLongSynchronizer.ConditionObject

Condition implementation for a AbstractQueuedLongSynchronizer serving as the basis of a Lock implementation.

pack-priv static class
pack-priv abstract static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static final int
pack-priv static final int
private transient volatile AbstractQueuedLongSynchronizer.Node
head

Head of the wait queue, lazily initialized.

private static final long
private static final long
private volatile long
state

The synchronization state.

private static final long
private transient volatile AbstractQueuedLongSynchronizer.Node
tail

Tail of the wait queue.

private static final long
private static final Unsafe
U

pack-priv static final int

Constructor Summary

AccessConstructor and Description
public
AbstractQueuedLongSynchronizer()

Constructor for subclasses to call.

Method Summary

Modifier and TypeMethod and Description
pack-priv final int

Returns:

positive if acquired, 0 if timed out, negative if interrupted
acquire
(AbstractQueuedLongSynchronizer.Node
null unless a reacquiring Condition
node
,
long
the acquire argument
arg
,
boolean
true if shared mode else exclusive
shared
,
boolean
if abort and return negative on interrupt
interruptible
,
boolean
if true use timed waits
timed
,
long
if timed, the System.nanoTime value to timeout
time
)

Main acquire method, invoked by all exported acquire methods.

public final void
acquire(long
the acquire argument. This value is conveyed to tryAcquire but is otherwise uninterpreted and can represent anything you like.
arg
)

Acquires in exclusive mode, ignoring interrupts.

public final void
acquireInterruptibly(long
the acquire argument. This value is conveyed to tryAcquire but is otherwise uninterpreted and can represent anything you like.
arg
)

Acquires in exclusive mode, aborting if interrupted.

private int
acquireOnOOME(boolean shared, long arg)

Spin-waits with backoff; used only upon OOME failures during acquire.

public final void
acquireShared(long
the acquire argument. This value is conveyed to tryAcquireShared but is otherwise uninterpreted and can represent anything you like.
arg
)

Acquires in shared mode, ignoring interrupts.

public final void
acquireSharedInterruptibly(long
the acquire argument. This value is conveyed to tryAcquireShared but is otherwise uninterpreted and can represent anything you like.
arg
)

Acquires in shared mode, aborting if interrupted.

pack-priv final boolean
apparentlyFirstQueuedIsExclusive()

Returns true if the apparent first queued thread, if one exists, is waiting in exclusive mode.

private int
cancelAcquire(AbstractQueuedLongSynchronizer.Node
the node (may be null if cancelled before enqueuing)
node
,
boolean
true if thread interrupted
interrupted
,
boolean
if should report interruption vs reset
interruptible
)

Cancels an ongoing attempt to acquire.

private boolean
private void
cleanQueue()

Possibly repeatedly traverses from tail, unsplicing cancelled nodes until none are found.

protected final boolean

Returns:

true if successful. False return indicates that the actual value was not equal to the expected value.
compareAndSetState
(long
the expected value
expect
,
long
the new value
update
)

Atomically sets synchronization state to the given updated value if the current state value equals the expected value.

pack-priv final void
enqueue(AbstractQueuedLongSynchronizer.ConditionNode node)

Enqueues the node unless null.

public final Collection<Thread>

Returns:

the collection of threads
getExclusiveQueuedThreads
()

Returns a collection containing threads that may be waiting to acquire in exclusive mode.

public final Thread

Returns:

the first (longest-waiting) thread in the queue, or null if no threads are currently queued
getFirstQueuedThread
()

Returns the first (longest-waiting) thread in the queue, or null if no threads are currently queued.

public final Collection<Thread>

Returns:

the collection of threads
getQueuedThreads
()

Returns a collection containing threads that may be waiting to acquire.

public final int

Returns:

the estimated number of threads waiting to acquire
getQueueLength
()

Returns an estimate of the number of threads waiting to acquire.

public final Collection<Thread>

Returns:

the collection of threads
getSharedQueuedThreads
()

Returns a collection containing threads that may be waiting to acquire in shared mode.

protected final long

Returns:

current state value
getState
()

Returns the current value of synchronization state.

public final Collection<Thread>

Returns:

the collection of threads
getWaitingThreads
(AbstractQueuedLongSynchronizer.ConditionObject
the condition
condition
)

Returns a collection containing those threads that may be waiting on the given condition associated with this synchronizer.

public final int

Returns:

the estimated number of waiting threads
getWaitQueueLength
(AbstractQueuedLongSynchronizer.ConditionObject
the condition
condition
)

Returns an estimate of the number of threads waiting on the given condition associated with this synchronizer.

public final boolean

Returns:

true if there has ever been contention
hasContended
()

Queries whether any threads have ever contended to acquire this synchronizer; that is, if an acquire method has ever blocked.

public final boolean

Returns:

true if there is a queued thread preceding the current thread, and false if the current thread is at the head of the queue or the queue is empty
hasQueuedPredecessors
()

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

public final boolean

Returns:

true if there may be other threads waiting to acquire
hasQueuedThreads
()

Queries whether any threads are waiting to acquire.

public final boolean

Returns:

true if there are any waiting threads
hasWaiters
(AbstractQueuedLongSynchronizer.ConditionObject
the condition
condition
)

Queries whether any threads are waiting on the given condition associated with this synchronizer.

pack-priv final boolean
isEnqueued(AbstractQueuedLongSynchronizer.Node node)

Returns true if node is found in traversal from tail

protected boolean

Returns:

true if synchronization is held exclusively; false otherwise
isHeldExclusively
()

Returns true if synchronization is held exclusively with respect to the current (calling) thread.

public final boolean

Returns:

true if the given thread is on the queue
isQueued
(Thread
the thread
thread
)

Returns true if the given thread is currently queued.

public final boolean

Returns:

true if owned
owns
(AbstractQueuedLongSynchronizer.ConditionObject
the condition
condition
)

Queries whether the given ConditionObject uses this synchronizer as its lock.

public final boolean

Returns:

the value returned from tryRelease
release
(long
the release argument. This value is conveyed to tryRelease but is otherwise uninterpreted and can represent anything you like.
arg
)

Releases in exclusive mode.

public final boolean

Returns:

the value returned from tryReleaseShared
releaseShared
(long
the release argument. This value is conveyed to tryReleaseShared but is otherwise uninterpreted and can represent anything you like.
arg
)

Releases in shared mode.

protected final void
setState(long
the new state value
newState
)

Sets the value of synchronization state.

private static void
signalNext(AbstractQueuedLongSynchronizer.Node h)

Wakes up the successor of given node, if one exists, and unsets its WAITING status to avoid park race.

private static void
signalNextIfShared(AbstractQueuedLongSynchronizer.Node h)

Wakes up the given node if in shared mode

public String

Returns:

a string identifying this synchronizer, as well as its state
toString
()

Overrides java.lang.Object.toString.

Returns a string identifying this synchronizer, as well as its state.

protected boolean

Returns:

true if successful. Upon success, this object has been acquired.
tryAcquire
(long
the acquire argument. This value is always the one passed to an acquire method, or is the value saved on entry to a condition wait. The value is otherwise uninterpreted and can represent anything you like.
arg
)

Attempts to acquire in exclusive mode.

public final boolean

Returns:

true if acquired; false if timed out
tryAcquireNanos
(long
the acquire argument. This value is conveyed to tryAcquire but is otherwise uninterpreted and can represent anything you like.
arg
,
long
the maximum number of nanoseconds to wait
nanosTimeout
)

Attempts to acquire in exclusive mode, aborting if interrupted, and failing if the given timeout elapses.

protected long

Returns:

a negative value on failure; zero if acquisition in shared mode succeeded but no subsequent shared-mode acquire can succeed; and a positive value if acquisition in shared mode succeeded and subsequent shared-mode acquires might also succeed, in which case a subsequent waiting thread must check availability. (Support for three different return values enables this method to be used in contexts where acquires only sometimes act exclusively.) Upon success, this object has been acquired.
tryAcquireShared
(long
the acquire argument. This value is always the one passed to an acquire method, or is the value saved on entry to a condition wait. The value is otherwise uninterpreted and can represent anything you like.
arg
)

Attempts to acquire in shared mode.

public final boolean

Returns:

true if acquired; false if timed out
tryAcquireSharedNanos
(long
the acquire argument. This value is conveyed to tryAcquireShared but is otherwise uninterpreted and can represent anything you like.
arg
,
long
the maximum number of nanoseconds to wait
nanosTimeout
)

Attempts to acquire in shared mode, aborting if interrupted, and failing if the given timeout elapses.

private AbstractQueuedLongSynchronizer.Node
tryInitializeHead()

Tries to CAS a new dummy node for head.

protected boolean

Returns:

true if this object is now in a fully released state, so that any waiting threads may attempt to acquire; and false otherwise.
tryRelease
(long
the release argument. This value is always the one passed to a release method, or the current state value upon entry to a condition wait. The value is otherwise uninterpreted and can represent anything you like.
arg
)

Attempts to set the state to reflect a release in exclusive mode.

protected boolean

Returns:

true if this release of shared mode may permit a waiting acquire (shared or exclusive) to succeed; and false otherwise
tryReleaseShared
(long
the release argument. This value is always the one passed to a release method, or the current state value upon entry to a condition wait. The value is otherwise uninterpreted and can represent anything you like.
arg
)

Attempts to set the state to reflect a release in shared mode.

Inherited from java.util.concurrent.locks.AbstractOwnableSynchronizer:
getExclusiveOwnerThreadsetExclusiveOwnerThread