| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public abstract class AbstractQueuedLongSynchronizer extends AbstractOwnableSynchronizer implements Serializable
A version of {@link 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 {@link AbstractQueuedSynchronizer} for usage notes and examples.
Nested Class Summary | |
---|---|
class |
Condition implementation for a java.util.concurrent.locks.AbstractQueuedLongSynchronizer serving as the basis of a java.util.concurrent.locks.Lock implementation. |
Constructor Summary | |
---|---|
protected |
Creates a new AbstractQueuedLongSynchronizer instance with initial synchronization state of zero. |
Method Summary | |
---|---|
void |
acquire(long arg) Acquires in exclusive mode, ignoring interrupts. |
void |
acquireInterruptibly(long arg) Acquires in exclusive mode, aborting if interrupted. |
void |
acquireShared(long arg) Acquires in shared mode, ignoring interrupts. |
void |
acquireSharedInterruptibly(long arg) Acquires in shared mode, aborting if interrupted. |
protected boolean |
compareAndSetState(long expect, long update) Atomically sets synchronization state to the given updated value if the current state value equals the expected value. |
Collection |
Returns a collection containing threads that may be waiting to acquire in exclusive mode. |
Thread |
Returns the first (longest-waiting) thread in the queue, or if no threads are currently queued. |
Collection |
Returns a collection containing threads that may be waiting to acquire. |
int |
Returns an estimate of the number of threads waiting to acquire. |
Collection |
Returns a collection containing threads that may be waiting to acquire in shared mode. |
protected long |
getState() Returns the current value of synchronization state. |
Collection |
Returns a collection containing those threads that may be waiting on the given condition associated with this synchronizer. |
int |
Returns an estimate of the number of threads waiting on the given condition associated with this synchronizer. |
boolean |
Queries whether any threads have ever contended to acquire this synchronizer; that is if an acquire method has ever blocked. |
boolean |
Queries whether any threads are waiting to acquire. |
boolean |
Queries whether any threads are waiting on the given condition associated with this synchronizer. |
protected boolean |
Returns if synchronization is held exclusively with respect to the current (calling) thread. |
boolean |
Returns true if the given thread is currently queued. |
boolean |
Queries whether the given ConditionObject uses this synchronizer as its lock. |
boolean |
release(long arg) Releases in exclusive mode. |
boolean |
releaseShared(long arg) Releases in shared mode. |
protected void |
setState(long newState) Sets the value of synchronization state. |
String |
toString() Returns a string identifying this synchronizer, as well as its state. |
protected boolean |
tryAcquire(long arg) Attempts to acquire in exclusive mode. |
boolean |
tryAcquireNanos(long arg, long nanosTimeout) Attempts to acquire in exclusive mode, aborting if interrupted, and failing if the given timeout elapses. |
protected long |
tryAcquireShared(long arg) Attempts to acquire in shared mode. |
boolean |
tryAcquireSharedNanos(long arg, long nanosTimeout) Attempts to acquire in shared mode, aborting if interrupted, and failing if the given timeout elapses. |
protected boolean |
tryRelease(long arg) Attempts to set the state to reflect a release in exclusive mode. |
protected boolean |
tryReleaseShared(long arg) Attempts to set the state to reflect a release in shared mode. |
Methods inherited from class java.util.concurrent.locks.AbstractOwnableSynchronizer |
---|
getExclusiveOwnerThread, setExclusiveOwnerThread |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected AbstractQueuedLongSynchronizer()
Method Detail |
---|
public final void acquire(long arg)
arg
- the acquire argument. This value is conveyed to
{@link #tryAcquire} but is otherwise uninterpreted and
can represent anything you like.public final void acquireInterruptibly(long arg) throws InterruptedException
arg
- the acquire argument. This value is conveyed to
{@link #tryAcquire} but is otherwise uninterpreted and
can represent anything you like.InterruptedException
- if the current thread is interruptedpublic final void acquireShared(long arg)
arg
- the acquire argument. This value is conveyed to
{@link #tryAcquireShared} but is otherwise uninterpreted
and can represent anything you like.public final void acquireSharedInterruptibly(long arg) throws InterruptedException
arg
- the acquire argument.
This value is conveyed to {@link #tryAcquireShared} but is
otherwise uninterpreted and can represent anything
you like.InterruptedException
- if the current thread is interruptedprotected final boolean compareAndSetState(long expect, long update)
expect
- the expected valueupdate
- the new valuepublic final Collection getExclusiveQueuedThreads()
public final Thread getFirstQueuedThread()
In this implementation, this operation normally returns in constant time, but may iterate upon contention if other threads are concurrently modifying the queue.
public final Collection getQueuedThreads()
public final int getQueueLength()
public final Collection getSharedQueuedThreads()
protected final long getState()
public final Collection getWaitingThreads(AbstractQueuedLongSynchronizer.ConditionObject condition)
condition
- the conditionpublic final int getWaitQueueLength(AbstractQueuedLongSynchronizer.ConditionObject condition)
condition
- the conditionpublic final boolean hasContended()
In this implementation, this operation returns in constant time.
public final boolean hasQueuedThreads()
In this implementation, this operation returns in constant time.
public final boolean hasWaiters(AbstractQueuedLongSynchronizer.ConditionObject condition)
condition
- the conditionprotected boolean isHeldExclusively()
The default implementation throws {@link UnsupportedOperationException}. This method is invoked internally only within {@link ConditionObject} methods, so need not be defined if conditions are not used.
public final boolean isQueued(Thread thread)
This implementation traverses the queue to determine presence of the given thread.
thread
- the threadpublic final boolean owns(AbstractQueuedLongSynchronizer.ConditionObject condition)
condition
- the conditionpublic final boolean release(long arg)
arg
- the release argument. This value is conveyed to
{@link #tryRelease} but is otherwise uninterpreted and
can represent anything you like.public final boolean releaseShared(long arg)
arg
- the release argument. This value is conveyed to
{@link #tryReleaseShared} but is otherwise uninterpreted
and can represent anything you like.protected final void setState(long newState)
newState
- the new state valuepublic String toString()
toString
in class Object
protected boolean tryAcquire(long arg)
This method is always invoked by the thread performing acquire. If this method reports failure, the acquire method may queue the thread, if it is not already queued, until it is signalled by a release from some other thread. This can be used to implement method {@link Lock#tryLock()}.
The default implementation throws {@link UnsupportedOperationException}.
arg
- 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.public final boolean tryAcquireNanos(long arg, long nanosTimeout) throws InterruptedException
arg
- the acquire argument. This value is conveyed to
{@link #tryAcquire} but is otherwise uninterpreted and
can represent anything you like.nanosTimeout
- the maximum number of nanoseconds to waitInterruptedException
- if the current thread is interruptedprotected long tryAcquireShared(long arg)
This method is always invoked by the thread performing acquire. If this method reports failure, the acquire method may queue the thread, if it is not already queued, until it is signalled by a release from some other thread.
The default implementation throws {@link UnsupportedOperationException}.
arg
- 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.public final boolean tryAcquireSharedNanos(long arg, long nanosTimeout) throws InterruptedException
arg
- the acquire argument. This value is conveyed to
{@link #tryAcquireShared} but is otherwise uninterpreted
and can represent anything you like.nanosTimeout
- the maximum number of nanoseconds to waitInterruptedException
- if the current thread is interruptedprotected boolean tryRelease(long arg)
This method is always invoked by the thread performing release.
The default implementation throws {@link UnsupportedOperationException}.
arg
- 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.protected boolean tryReleaseShared(long arg)
This method is always invoked by the thread performing release.
The default implementation throws {@link UnsupportedOperationException}.
arg
- 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.
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |