This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


java.util.concurrent.locks
class AbstractQueuedLongSynchronizer

java.lang.Object extended by java.util.concurrent.locks.AbstractOwnableSynchronizer extended by java.util.concurrent.locks.AbstractQueuedLongSynchronizer
All Implemented Interfaces:
Serializable

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

          Acquires in exclusive mode, aborting if interrupted.
 void
acquireShared(long arg)

          Acquires in shared mode, ignoring interrupts.
 void

          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

          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
isQueued(Thread thread)

          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

          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

AbstractQueuedLongSynchronizer

protected AbstractQueuedLongSynchronizer()
Creates a new AbstractQueuedLongSynchronizer instance with initial synchronization state of zero.

Method Detail

acquire

public final void acquire(long arg)
Acquires in exclusive mode, ignoring interrupts. Implemented by invoking at least once {@link #tryAcquire}, returning on success. Otherwise the thread is queued, possibly repeatedly blocking and unblocking, invoking {@link #tryAcquire} until success. This method can be used to implement method {@link Lock#lock}.

Parameters:
arg - the acquire argument. This value is conveyed to {@link #tryAcquire} but is otherwise uninterpreted and can represent anything you like.

acquireInterruptibly

public final void acquireInterruptibly(long arg)
                                throws InterruptedException
Acquires in exclusive mode, aborting if interrupted. Implemented by first checking interrupt status, then invoking at least once {@link #tryAcquire}, returning on success. Otherwise the thread is queued, possibly repeatedly blocking and unblocking, invoking {@link #tryAcquire} until success or the thread is interrupted. This method can be used to implement method {@link Lock#lockInterruptibly}.

Parameters:
arg - the acquire argument. This value is conveyed to {@link #tryAcquire} but is otherwise uninterpreted and can represent anything you like.
Throws:
InterruptedException - if the current thread is interrupted

acquireShared

public final void acquireShared(long arg)
Acquires in shared mode, ignoring interrupts. Implemented by first invoking at least once {@link #tryAcquireShared}, returning on success. Otherwise the thread is queued, possibly repeatedly blocking and unblocking, invoking {@link #tryAcquireShared} until success.

Parameters:
arg - the acquire argument. This value is conveyed to {@link #tryAcquireShared} but is otherwise uninterpreted and can represent anything you like.

acquireSharedInterruptibly

public final void acquireSharedInterruptibly(long arg)
                                      throws InterruptedException
Acquires in shared mode, aborting if interrupted. Implemented by first checking interrupt status, then invoking at least once {@link #tryAcquireShared}, returning on success. Otherwise the thread is queued, possibly repeatedly blocking and unblocking, invoking {@link #tryAcquireShared} until success or the thread is interrupted.

Parameters:
arg - the acquire argument. This value is conveyed to {@link #tryAcquireShared} but is otherwise uninterpreted and can represent anything you like.
Throws:
InterruptedException - if the current thread is interrupted

compareAndSetState

protected final boolean compareAndSetState(long expect,
                                           long update)
Atomically sets synchronization state to the given updated value if the current state value equals the expected value. This operation has memory semantics of a volatile read and write.

Parameters:
expect - the expected value
update - the new value
Returns:
true if successful. False return indicates that the actual value was not equal to the expected value.

getExclusiveQueuedThreads

public final Collection getExclusiveQueuedThreads()
Returns a collection containing threads that may be waiting to acquire in exclusive mode. This has the same properties as {@link #getQueuedThreads} except that it only returns those threads waiting due to an exclusive acquire.

Returns:
the collection of threads

getFirstQueuedThread

public final Thread getFirstQueuedThread()
Returns the first (longest-waiting) thread in the queue, or {@code null} if no threads are currently queued.

In this implementation, this operation normally returns in constant time, but may iterate upon contention if other threads are concurrently modifying the queue.

Returns:
the first (longest-waiting) thread in the queue, or {@code null} if no threads are currently queued

getQueuedThreads

public final Collection getQueuedThreads()
Returns a collection containing threads that may be waiting to acquire. Because the actual set of threads may change dynamically while constructing this result, the returned collection is only a best-effort estimate. The elements of the returned collection are in no particular order. This method is designed to facilitate construction of subclasses that provide more extensive monitoring facilities.

Returns:
the collection of threads

getQueueLength

public final int getQueueLength()
Returns an estimate of the number of threads waiting to acquire. The value is only an estimate because the number of threads may change dynamically while this method traverses internal data structures. This method is designed for use in monitoring system state, not for synchronization control.

Returns:
the estimated number of threads waiting to acquire

getSharedQueuedThreads

public final Collection getSharedQueuedThreads()
Returns a collection containing threads that may be waiting to acquire in shared mode. This has the same properties as {@link #getQueuedThreads} except that it only returns those threads waiting due to a shared acquire.

Returns:
the collection of threads

getState

protected final long getState()
Returns the current value of synchronization state. This operation has memory semantics of a volatile read.

Returns:
current state value

getWaitingThreads

public final Collection getWaitingThreads(AbstractQueuedLongSynchronizer.ConditionObject condition)
Returns a collection containing those threads that may be waiting on the given condition associated with this synchronizer. Because the actual set of threads may change dynamically while constructing this result, the returned collection is only a best-effort estimate. The elements of the returned collection are in no particular order.

Parameters:
condition - the condition
Returns:
the collection of threads

getWaitQueueLength

public final int getWaitQueueLength(AbstractQueuedLongSynchronizer.ConditionObject condition)
Returns an estimate of the number of threads waiting on the given condition associated with this synchronizer. Note that because timeouts and interrupts may occur at any time, the estimate serves only as an upper bound on the actual number of waiters. This method is designed for use in monitoring of the system state, not for synchronization control.

Parameters:
condition - the condition
Returns:
the estimated number of waiting threads

hasContended

public final boolean hasContended()
Queries whether any threads have ever contended to acquire this synchronizer; that is if an acquire method has ever blocked.

In this implementation, this operation returns in constant time.

Returns:
{@code true} if there has ever been contention

hasQueuedThreads

public final boolean hasQueuedThreads()
Queries whether any threads are waiting to acquire. Note that because cancellations due to interrupts and timeouts may occur at any time, a {@code true} return does not guarantee that any other thread will ever acquire.

In this implementation, this operation returns in constant time.

Returns:
{@code true} if there may be other threads waiting to acquire

hasWaiters

public final boolean hasWaiters(AbstractQueuedLongSynchronizer.ConditionObject condition)
Queries whether any threads are waiting on the given condition associated with this synchronizer. Note that because timeouts and interrupts may occur at any time, a true return does not guarantee that a future signal will awaken any threads. This method is designed primarily for use in monitoring of the system state.

Parameters:
condition - the condition
Returns:
true if there are any waiting threads

isHeldExclusively

protected boolean isHeldExclusively()
Returns {@code true} if synchronization is held exclusively with respect to the current (calling) thread. This method is invoked upon each call to a non-waiting {@link ConditionObject} method. (Waiting methods instead invoke {@link #release}.)

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.

Returns:
{@code true} if synchronization is held exclusively; {@code false} otherwise

isQueued

public final boolean isQueued(Thread thread)
Returns true if the given thread is currently queued.

This implementation traverses the queue to determine presence of the given thread.

Parameters:
thread - the thread
Returns:
{@code true} if the given thread is on the queue

owns

public final boolean owns(AbstractQueuedLongSynchronizer.ConditionObject condition)
Queries whether the given ConditionObject uses this synchronizer as its lock.

Parameters:
condition - the condition
Returns:
true if owned

release

public final boolean release(long arg)
Releases in exclusive mode. Implemented by unblocking one or more threads if {@link #tryRelease} returns true. This method can be used to implement method {@link Lock#unlock}.

Parameters:
arg - the release argument. This value is conveyed to {@link #tryRelease} but is otherwise uninterpreted and can represent anything you like.
Returns:
the value returned from {@link #tryRelease}

releaseShared

public final boolean releaseShared(long arg)
Releases in shared mode. Implemented by unblocking one or more threads if {@link #tryReleaseShared} returns true.

Parameters:
arg - the release argument. This value is conveyed to {@link #tryReleaseShared} but is otherwise uninterpreted and can represent anything you like.
Returns:
the value returned from {@link #tryReleaseShared}

setState

protected final void setState(long newState)
Sets the value of synchronization state. This operation has memory semantics of a volatile write.

Parameters:
newState - the new state value

toString

public String toString()
Returns a string identifying this synchronizer, as well as its state. The state, in brackets, includes the String {@code "State ="} followed by the current value of {@link #getState}, and either {@code "nonempty"} or {@code "empty"} depending on whether the queue is empty.

Overrides:
toString in class Object
Returns:
a string identifying this synchronizer, as well as its state

tryAcquire

protected boolean tryAcquire(long arg)
Attempts to acquire in exclusive mode. This method should query if the state of the object permits it to be acquired in the exclusive mode, and if so to acquire it.

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}.

Parameters:
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.
Returns:
{@code true} if successful. Upon success, this object has been acquired.

tryAcquireNanos

public final boolean tryAcquireNanos(long arg,
                                     long nanosTimeout)
                              throws InterruptedException
Attempts to acquire in exclusive mode, aborting if interrupted, and failing if the given timeout elapses. Implemented by first checking interrupt status, then invoking at least once {@link #tryAcquire}, returning on success. Otherwise, the thread is queued, possibly repeatedly blocking and unblocking, invoking {@link #tryAcquire} until success or the thread is interrupted or the timeout elapses. This method can be used to implement method {@link Lock#tryLock(long, TimeUnit)}.

Parameters:
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 wait
Returns:
{@code true} if acquired; {@code false} if timed out
Throws:
InterruptedException - if the current thread is interrupted

tryAcquireShared

protected long tryAcquireShared(long arg)
Attempts to acquire in shared mode. This method should query if the state of the object permits it to be acquired in the shared mode, and if so to acquire it.

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}.

Parameters:
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.
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.

tryAcquireSharedNanos

public final boolean tryAcquireSharedNanos(long arg,
                                           long nanosTimeout)
                                    throws InterruptedException
Attempts to acquire in shared mode, aborting if interrupted, and failing if the given timeout elapses. Implemented by first checking interrupt status, then invoking at least once {@link #tryAcquireShared}, returning on success. Otherwise, the thread is queued, possibly repeatedly blocking and unblocking, invoking {@link #tryAcquireShared} until success or the thread is interrupted or the timeout elapses.

Parameters:
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 wait
Returns:
{@code true} if acquired; {@code false} if timed out
Throws:
InterruptedException - if the current thread is interrupted

tryRelease

protected boolean tryRelease(long arg)
Attempts to set the state to reflect a release in exclusive mode.

This method is always invoked by the thread performing release.

The default implementation throws {@link UnsupportedOperationException}.

Parameters:
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.
Returns:
{@code true} if this object is now in a fully released state, so that any waiting threads may attempt to acquire; and {@code false} otherwise.

tryReleaseShared

protected boolean tryReleaseShared(long arg)
Attempts to set the state to reflect a release in shared mode.

This method is always invoked by the thread performing release.

The default implementation throws {@link UnsupportedOperationException}.

Parameters:
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.
Returns:
{@code true} if this release of shared mode may permit a waiting acquire (shared or exclusive) to succeed; and {@code false} otherwise


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.