Class ThreadLock
- java.lang.Object
-
- de.aristaflow.adept2.util.locking.ReentrantLock<Thread>
-
- de.aristaflow.adept2.util.locking.ThreadLock
-
public class ThreadLock extends ReentrantLock<Thread>
This class provides a reentrant read/write-lock based on threads. When using theObjectEqualityLockCount
together with this class, one has the same behaviour asReentrantReadWriteLock
.
It is merely for convenience purpose and allow type safety (Java does not allowReentrantLock<Thread>.class
).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.aristaflow.adept2.util.locking.ReentrantLock
ReentrantLock.Lock, ReentrantLock.ReadLock, ReentrantLock.WriteLock
-
-
Field Summary
-
Fields inherited from class de.aristaflow.adept2.util.locking.ReentrantLock
logger, notification, readLock, writeLock
-
-
Constructor Summary
Constructors Constructor Description ThreadLock(boolean exclusive, Logger logger)
Creates a newThreadLock
resemblingReentrantReadWriteLock
in non-exclusive mode, that is, it is based on threads, it usesObject.equals(Object)
and is either exclusive or it supports (non-exclusive) readers and (exclusive) writers.ThreadLock(Class<? extends LockCountManager<Thread>> lockCountManager, boolean exclusive, LockNotification<Thread> notification, Logger logger)
Creates a newThreadLock
using the designated lock count manager and the designated exclusive mode.ThreadLock(Class<? extends LockCountManager<Thread>> lockCountManager, boolean exclusive, Logger logger)
Creates a newThreadLock
using the designated lock count manager and the designated exclusive mode.ThreadLock(Logger logger)
Creates a newThreadLock
resemblingReentrantLock
, that is, it is based on threads, it usesObject.equals(Object)
and it is exclusive.
-
Method Summary
-
Methods inherited from class de.aristaflow.adept2.util.locking.ReentrantLock
invalidate, isReadLocked, isWriteLocked, readLock, writeLock
-
-
-
-
Constructor Detail
-
ThreadLock
public ThreadLock(Logger logger) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
Creates a newThreadLock
resemblingReentrantLock
, that is, it is based on threads, it usesObject.equals(Object)
and it is exclusive.- Parameters:
logger
- The logger for log messages.- Throws:
NoSuchMethodException
- Should never happen. If the object equality lock count manager has no constructor without parameters, aNouSuchMethodException
will be thrown.InstantiationException
- Should never happen. If the object equality lock count manager cannot be instantiated or does not have a parameterless constructor, anInstantiationException
will be thrown.IllegalAccessException
- Should never happen. If the object equality lock count manager class or its constructor is not accessible, anIllegalAccessException
will be thrown.InvocationTargetException
- If the constructor of the object equality lock count manager throws an exception, this will be wrapped by anInvocationTargetException
.
-
ThreadLock
public ThreadLock(boolean exclusive, Logger logger) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
Creates a newThreadLock
resemblingReentrantReadWriteLock
in non-exclusive mode, that is, it is based on threads, it usesObject.equals(Object)
and is either exclusive or it supports (non-exclusive) readers and (exclusive) writers.- Parameters:
exclusive
- Whether to create an exclusive lock or a read/write-lock.logger
- The logger for log messages.- Throws:
NoSuchMethodException
- Should never happen. If the object equality lock count manager has no constructor without parameters, aNouSuchMethodException
will be thrown.InstantiationException
- Should never happen. If the object equality lock count manager cannot be instantiated or does not have a parameterless constructor, anInstantiationException
will be thrown.IllegalAccessException
- Should never happen. If the object equality lock count manager class or its constructor is not accessible, anIllegalAccessException
will be thrown.InvocationTargetException
- If the constructor of the object equality lock count manager throws an exception, this will be wrapped by anInvocationTargetException
.
-
ThreadLock
public ThreadLock(Class<? extends LockCountManager<Thread>> lockCountManager, boolean exclusive, Logger logger) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
Creates a newThreadLock
using the designated lock count manager and the designated exclusive mode. This constructor is for usage byObjectLockManager
.- Parameters:
lockCountManager
- The manager counting locks for threads. 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.- Throws:
NoSuchMethodException
- Should never happen. If the object equality lock count manager has no constructor without parameters, aNouSuchMethodException
will be thrown.InstantiationException
- If the designated lock count manager class cannot be instantiated or does not have a parameterless constructor, anInstantiationException
will be thrown.IllegalAccessException
- If the designated lock count manager class or its constructor is not accessible, anIllegalAccessException
will be thrown.InvocationTargetException
- If the constructor of the object equality lock count manager throws an exception, this will be wrapped by anInvocationTargetException
.
-
ThreadLock
public ThreadLock(Class<? extends LockCountManager<Thread>> lockCountManager, boolean exclusive, LockNotification<Thread> notification, Logger logger) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
Creates a newThreadLock
using the designated lock count manager and the designated exclusive mode. 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. This constructor is for usage byObjectLockManager
.- Parameters:
lockCountManager
- The manager counting locks for threads. 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 isnull
, no notification will be sent.logger
- The logger for log messages.- Throws:
NoSuchMethodException
- Should never happen. If the object equality lock count manager has no constructor without parameters, aNouSuchMethodException
will be thrown.InstantiationException
- If the designated lock count manager class cannot be instantiated or does not have a parameterless constructor, anInstantiationException
will be thrown.IllegalAccessException
- If the designated lock count manager class or its constructor is not accessible, anIllegalAccessException
will be thrown.InvocationTargetException
- If the constructor of the object equality lock count manager throws an exception, this will be wrapped by anInvocationTargetException
.
-
-