| |
|
| java.lang.Object java.util.concurrent.locks.ReentrantReadWriteLock
Inner Class :final static class NonfairSync extends Sync | |
Inner Class :final static class FairSync extends Sync | |
Constructor Summary | |
public | ReentrantReadWriteLock() Creates a new
ReentrantReadWriteLock with
default (nonfair) ordering properties. | public | ReentrantReadWriteLock(boolean fair) Creates a new
ReentrantReadWriteLock with
the given fairness policy. |
Method Summary | |
protected Thread | getOwner() Returns the thread that currently owns the write lock, or
null if not owned. | final public int | getQueueLength() Returns an estimate of the number of threads waiting to acquire
either the read or write lock. | protected Collection<Thread> | getQueuedReaderThreads() Returns a collection containing threads that may be waiting to
acquire the read lock. | protected Collection<Thread> | getQueuedThreads() Returns a collection containing threads that may be waiting to
acquire either the read or write lock. | protected Collection<Thread> | getQueuedWriterThreads() Returns a collection containing threads that may be waiting to
acquire the write lock. | public int | getReadHoldCount() Queries the number of reentrant read holds on this lock by the
current thread. | public int | getReadLockCount() Queries the number of read locks held for this lock. | public int | getWaitQueueLength(Condition condition) Returns an estimate of the number of threads waiting on the
given condition associated with the write lock. | protected Collection<Thread> | getWaitingThreads(Condition condition) Returns a collection containing those threads that may be
waiting on the given condition associated with the write lock.
Because the actual set of threads may change dynamically while
constructing this result, the returned collection is only a
best-effort estimate. | public int | getWriteHoldCount() Queries the number of reentrant write holds on this lock by the
current thread. | final public boolean | hasQueuedThread(Thread thread) Queries whether the given thread is waiting to acquire either
the read or write lock. | final public boolean | hasQueuedThreads() Queries whether any threads are waiting to acquire the read or
write lock. | public boolean | hasWaiters(Condition condition) Queries whether any threads are waiting on the given condition
associated with the write lock. | final public boolean | isFair() Returns
true if this lock has fairness set true. | public boolean | isWriteLocked() Queries if the write lock is held by any thread. | public boolean | isWriteLockedByCurrentThread() Queries if the write lock is held by the current thread. | public ReentrantReadWriteLock.ReadLock | readLock() | public String | toString() Returns a string identifying this lock, as well as its lock state. | public ReentrantReadWriteLock.WriteLock | writeLock() |
ReentrantReadWriteLock | public ReentrantReadWriteLock()(Code) | | Creates a new
ReentrantReadWriteLock with
default (nonfair) ordering properties.
|
ReentrantReadWriteLock | public ReentrantReadWriteLock(boolean fair)(Code) | | Creates a new
ReentrantReadWriteLock with
the given fairness policy.
Parameters: fair - true if this lock should use a fair ordering policy |
getOwner | protected Thread getOwner()(Code) | | Returns the thread that currently owns the write lock, or
null if not owned. When this method is called by a
thread that is not the owner, the return value reflects a
best-effort approximation of current lock status. For example,
the owner may be momentarily
null even if there are
threads trying to acquire the lock but have not yet done so.
This method is designed to facilitate construction of
subclasses that provide more extensive lock monitoring
facilities.
the owner, or null if not owned |
getQueueLength | final public int getQueueLength()(Code) | | Returns an estimate of the number of threads waiting to acquire
either the read or write lock. 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 of the system state, not for
synchronization control.
the estimated number of threads waiting for this lock |
getQueuedReaderThreads | protected Collection<Thread> getQueuedReaderThreads()(Code) | | Returns a collection containing threads that may be waiting to
acquire the read lock. 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 lock monitoring facilities.
the collection of threads |
getQueuedThreads | protected Collection<Thread> getQueuedThreads()(Code) | | Returns a collection containing threads that may be waiting to
acquire either the read or write lock. 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.
the collection of threads |
getQueuedWriterThreads | protected Collection<Thread> getQueuedWriterThreads()(Code) | | Returns a collection containing threads that may be waiting to
acquire the write lock. 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 lock monitoring facilities.
the collection of threads |
getReadHoldCount | public int getReadHoldCount()(Code) | | Queries the number of reentrant read holds on this lock by the
current thread. A reader thread has a hold on a lock for
each lock action that is not matched by an unlock action.
the number of holds on the read lock by the current thread,or zero if the read lock is not held by the current thread since: 1.6 |
getReadLockCount | public int getReadLockCount()(Code) | | Queries the number of read locks held for this lock. This
method is designed for use in monitoring system state, not for
synchronization control.
the number of read locks held. |
getWaitQueueLength | public int getWaitQueueLength(Condition condition)(Code) | | Returns an estimate of the number of threads waiting on the
given condition associated with the write lock. 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 the estimated number of waiting threads throws: IllegalMonitorStateException - if this lock is not held throws: IllegalArgumentException - if the given condition isnot associated with this lock throws: NullPointerException - if the condition is null |
getWaitingThreads | protected Collection<Thread> getWaitingThreads(Condition condition)(Code) | | Returns a collection containing those threads that may be
waiting on the given condition associated with the write lock.
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 condition monitoring facilities.
Parameters: condition - the condition the collection of threads throws: IllegalMonitorStateException - if this lock is not held throws: IllegalArgumentException - if the given condition isnot associated with this lock throws: NullPointerException - if the condition is null |
getWriteHoldCount | public int getWriteHoldCount()(Code) | | Queries the number of reentrant write holds on this lock by the
current thread. A writer thread has a hold on a lock for
each lock action that is not matched by an unlock action.
the number of holds on the write lock by the current thread,or zero if the write lock is not held by the current thread |
hasQueuedThread | final public boolean hasQueuedThread(Thread thread)(Code) | | Queries whether the given thread is waiting to acquire either
the read or write lock. Note that because cancellations may
occur at any time, a
true return does not guarantee
that this thread will ever acquire a lock. This method is
designed primarily for use in monitoring of the system state.
Parameters: thread - the thread true if the given thread is queued waiting for this lock throws: NullPointerException - if the thread is null |
hasQueuedThreads | final public boolean hasQueuedThreads()(Code) | | Queries whether any threads are waiting to acquire the read or
write lock. Note that because cancellations may occur at any
time, a
true return does not guarantee that any other
thread will ever acquire a lock. This method is designed
primarily for use in monitoring of the system state.
true if there may be other threads waiting toacquire the lock |
hasWaiters | public boolean hasWaiters(Condition condition)(Code) | | Queries whether any threads are waiting on the given condition
associated with the write lock. 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 true if there are any waiting threads throws: IllegalMonitorStateException - if this lock is not held throws: IllegalArgumentException - if the given condition isnot associated with this lock throws: NullPointerException - if the condition is null |
isFair | final public boolean isFair()(Code) | | Returns
true if this lock has fairness set true.
true if this lock has fairness set true |
isWriteLocked | public boolean isWriteLocked()(Code) | | Queries if the write lock is held by any thread. This method is
designed for use in monitoring system state, not for
synchronization control.
true if any thread holds the write lock and false otherwise |
isWriteLockedByCurrentThread | public boolean isWriteLockedByCurrentThread()(Code) | | Queries if the write lock is held by the current thread.
true if the current thread holds the write lock and false otherwise |
toString | public String toString()(Code) | | Returns a string identifying this lock, as well as its lock state.
The state, in brackets, includes the String
"Write locks =" followed by the number of reentrantly held write locks, and the
String
"Read locks =" followed by the number of held
read locks.
a string identifying this lock, as well as its lock state |
|
|
|