T - The type of objects which may lock this reentrant lock (lock
owning object type).public class ReentrantLock<T>
extends java.lang.Object
ReentrantReadWriteLock| Modifier and Type | Class and Description |
|---|---|
class |
ReentrantLock.Lock
Represents a reentrant exclusive lock which allows only one object to hold
the lock but it may hold it multiple times.
|
protected class |
ReentrantLock.ReadLock
Represents a read lock which allows multiple objects to hold the lock
simultaneously and multiple times but blocks as soon as one object wants
a write lock.
|
protected class |
ReentrantLock.WriteLock
Represents a write lock which allows an object to hold the lock multiple
times. an object requesting a write lock blocks objects that request a
read lock.
|
| Modifier and Type | Field and Description |
|---|---|
protected java.util.logging.Logger |
logger
My logger.
|
protected LockNotification<T> |
notification
The notification to call directly but atomically after locking and
unlocking.
|
protected ReentrantLock.Lock |
readLock
The lock responsible for synchronising read access.
|
protected ReentrantLock.Lock |
writeLock
The lock responsible for synchronising write access.
|
| Constructor and Description |
|---|
ReentrantLock(java.lang.Class<? extends LockCountManager<? super T>> lockCountManager,
boolean exclusive,
LockNotification<T> notification,
java.util.logging.Logger logger)
Creates either a new exclusive lock or a new read/write-lock and using the
designated
LockCountManager for counting locks as well as
comparing objects. |
ReentrantLock(java.lang.Class<? extends LockCountManager<? super T>> lockCountManager,
boolean exclusive,
java.util.logging.Logger logger)
Creates either a new exclusive lock or a new read/write-lock and using the
designated
LockCountManager for counting locks as well as
comparing objects. |
ReentrantLock(LockCountManager<? super T> writeLockCountManager,
LockCountManager<? super T> readLockCountManager,
LockNotification<T> notification,
java.util.logging.Logger logger)
Creates either a new exclusive lock or a new read/write-lock and using the
LockCountManager for counting locks as well as comparing
objects. |
ReentrantLock(LockCountManager<? super T> lockCountManager,
LockNotification<T> notification,
java.util.logging.Logger logger)
Creates a new exclusive lock using the designated
LockCountManager for counting locks as well as comparing
objects. |
ReentrantLock(LockCountManager<? super T> lockCountManager,
java.util.logging.Logger logger)
Creates a new exclusive lock using the designated
LockCountManager for counting locks as well as comparing
objects. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
isReadLocked()
Returns whether this read/write-lock is currently read-locked or this
exclusive lock is currently locked.
|
boolean |
isWriteLocked()
Returns whether this read/write-lock is currently write-locked or this
exclusive lock is currently locked.
|
ReentrantLock.Lock |
readLock()
Returns the read-lock for this read/write-lock or the exclusive lock in
case of an exclusive lock.
|
ReentrantLock.Lock |
writeLock()
Returns the write-lock for this read/write-lock or the exclusive lock in
case of an exclusive lock.
|
protected final java.util.logging.Logger logger
protected final ReentrantLock.Lock writeLock
protected final ReentrantLock.Lock readLock
writeLock().protected final LockNotification<T> notification
null, no notification will be sent.public ReentrantLock(java.lang.Class<? extends LockCountManager<? super T>> lockCountManager, boolean exclusive, java.util.logging.Logger logger) throws java.lang.InstantiationException, java.lang.IllegalAccessException
LockCountManager for counting locks as well as
comparing objects.lockCountManager - The manager counting locks for objects. The
provided class needs an accessible (public) constructor without
parameters.exclusive - Whether to create an exclusive lock or a read/write-lock.logger - The logger for log messages.java.lang.InstantiationException - If the designated lock count manager class
cannot be instantiated or does not have a parameterless
constructor, an InstantiationException will be
thrown.java.lang.IllegalAccessException - If the designated lock count manager class
or its constructor is not accessible, an
IllegalAccessException will be thrown.public ReentrantLock(java.lang.Class<? extends LockCountManager<? super T>> lockCountManager, boolean exclusive, LockNotification<T> notification, java.util.logging.Logger logger) throws java.lang.InstantiationException, java.lang.IllegalAccessException
LockCountManager for counting locks as well as
comparing objects. The designated notification will be used for notifying a
successful lock or unlock while locking and unlocking, that is, the
notification will be atomically with respect to locking/unlocking.lockCountManager - The manager counting locks for objects. The
provided class needs an accessible (public) constructor without
parameters.exclusive - Whether to create an exclusive lock or a read/write-lock.notification - The notification to call directly but atomically after
locking and unlocking. If this is null, no
notification will be sent.logger - The logger for log messages.java.lang.InstantiationException - If the designated lock count manager class
cannot be instantiated or does not have a parameterless
constructor, an InstantiationException will be
thrown.java.lang.IllegalAccessException - If the designated lock count manager class
or its constructor is not accessible, an
IllegalAccessException will be thrown.public ReentrantLock(LockCountManager<? super T> lockCountManager, java.util.logging.Logger logger)
LockCountManager for counting locks as well as comparing
objects.lockCountManager - The manager counting locks for objects.logger - The logger for log messages.public ReentrantLock(LockCountManager<? super T> lockCountManager, LockNotification<T> notification, java.util.logging.Logger logger)
LockCountManager for counting locks as well as comparing
objects. The designated notification will be used for notifying a
successful lock or unlock while locking and unlocking, that is, the
notification will be atomically with respect to locking/unlocking.lockCountManager - The manager counting locks for objects.notification - The notification to call directly but atomically after
locking and unlocking. If this is null, no
notification will be sent.logger - The logger for log messages.public ReentrantLock(LockCountManager<? super T> writeLockCountManager, LockCountManager<? super T> readLockCountManager, LockNotification<T> notification, java.util.logging.Logger logger)
LockCountManager for counting locks as well as comparing
objects. If there is no lock count manager for the read lock or it equals
the lock count manager for the write lock, an exclusive lock will be
created, otherwise this will be read/write-lock. writeLockCountManager - The manager counting write locks for objects.readLockCountManager - The manager counting read locks for objects. If
this is null or equals the
writeLockCountManager, an exclusive lock will be
created.notification - The notification to call directly but atomically after
locking and unlocking. If this is null, no
notification will be sent.logger - The logger for log messages.public boolean isReadLocked()
public boolean isWriteLocked()
public ReentrantLock.Lock readLock()
public ReentrantLock.Lock writeLock()