public class LockableObject
extends AbstractQueuedSynchronizer
A bit simplified lock designed to be inherited by.
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected final boolean |
isHeldExclusively()Returns true if synchronization is held exclusively with
respect to the current (calling) thread. This method is invoked
upon each call to a ConditionObject method.
The default implementation throws UnsupportedOperationException. This method is invoked internally only within ConditionObject methods, so need not be defined if conditions are not used.
|
|
public final void |
lock()Acquires the lock, blocking until it becomes available. |
|
protected final boolean |
tryAcquire(int acquires)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 Lock#tryLock()#tryLock(). The default implementation throws UnsupportedOperationException.
|
|
protected final boolean |
tryRelease(int releases)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 UnsupportedOperationException.
|
|
public final void |
unlock()Releases one hold of the lock. |
| Methods inherited from class | Name |
|---|---|
class AbstractQueuedSynchronizer |
acquire, acquireInterruptibly, acquireShared, acquireSharedInterruptibly, equals, getClass, getExclusiveQueuedThreads, getFirstQueuedThread, getQueueLength, getQueuedThreads, getSharedQueuedThreads, getWaitQueueLength, getWaitingThreads, hasContended, hasQueuedPredecessors, hasQueuedThreads, hasWaiters, hashCode, isQueued, notify, notifyAll, owns, release, releaseShared, toString, tryAcquireNanos, tryAcquireSharedNanos, wait, wait, wait |
Returns true if synchronization is held exclusively with
respect to the current (calling) thread. This method is invoked
upon each call to a ConditionObject method.
The default implementation throws UnsupportedOperationException. This method is invoked internally only within ConditionObject methods, so need not be defined if conditions are not used.
true if synchronization is held exclusively;
false otherwiseAcquires the lock, blocking until it becomes available.
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 Lock#tryLock()#tryLock().
The default implementation throws 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.true if successful. Upon success, this object has
been acquired.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 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.true if this object is now in a fully released
state, so that any waiting threads may attempt to acquire;
and false otherwise.Releases one hold of the lock.