public class ReentrantLock.Lock
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected LockCountManager<? super T> |
lockCountManager
The manager for counting the lock acquisitions of an object and
encapsulating whether objects are equal.
|
protected java.util.concurrent.atomic.AtomicInteger |
waitersForLock
Counts how many threads are waiting to get this lock.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Lock(LockCountManager<? super T> lockCountManager)
Creates a new exclusive lock using the designated
LockCountManager for comparing objects. |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
currentLockingObject()
Retrieves a string representation of the object that is currently
holding the lock.
|
boolean |
hasLock(T object)
Determines if the designated object holds this lock.
|
boolean |
isLocked()
Returns whether this lock is currently locked by at least one object.
|
void |
lock(T object)
Provides the designated object with an exclusive lock.
|
void |
lock(T object,
long timeout)
Provides the designated object with an exclusive lock.
|
protected boolean |
notificationRequired()
Gets whether a notification of waiting threads is required.
|
int |
objectsWaitingToLock()
Returns the number of objects waiting to acquire this lock.
|
boolean |
unlock(T object)
Releases this lock for the designated object if it holds the lock.
|
protected final LockCountManager<? super T> lockCountManager
protected final java.util.concurrent.atomic.AtomicInteger waitersForLock
protected Lock(LockCountManager<? super T> lockCountManager)
LockCountManager for comparing objects.lockCountManager - The manager counting locks for objects.public void lock(T object) throws java.lang.InterruptedException
Calls Lock.lock(object, 0).
object - The object that requests an exclusive lock.java.lang.InterruptedException - If the thread is interrupted while waiting
for the lock, an InterruptedException will be
thrown.public void lock(T object, long timeout) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
Since the lock is reentrant, an object may acquire a lock multiple times. But it also has to release the lock per acquisition afterwards.
object - The object that requests an exclusive lock.timeout - The time to wait for the lock. A timeout <= 0 means to
wait forever (or until the lock is granted).java.lang.InterruptedException - If the thread is interrupted while waiting
for the lock, an InterruptedException will be
thrown.java.util.concurrent.TimeoutException - If the designated timeout elapsed before the
lock can be acquired, a TimeoutException will be
thrown.public boolean hasLock(T object)
object - The object that should be checked to hold this lock.public boolean isLocked()
public int objectsWaitingToLock()
public boolean unlock(T object)
object - The object for which the lock should be released.false will be returned.java.lang.IllegalArgumentException - If the designated object does not hold
this lock, an IllegalArgumentException will be
thrown.protected boolean notificationRequired()
public java.lang.String currentLockingObject()