Class ThreadLock


  • public class ThreadLock
    extends ReentrantLock<Thread>
    This class provides a reentrant read/write-lock based on threads. When using the ObjectEqualityLockCount together with this class, one has the same behaviour as ReentrantReadWriteLock.
    It is merely for convenience purpose and allow type safety (Java does not allow ReentrantLock<Thread>.class).
    Author:
    Ulrich Kreher
    • Constructor Detail

      • ThreadLock

        public ThreadLock​(Logger logger)
                   throws InstantiationException,
                          IllegalAccessException
        Creates a new ThreadLock resembling ReentrantLock, that is, it is based on threads, it uses Object.equals(Object) and it is exclusive.
        Parameters:
        logger - The logger for log messages.
        Throws:
        InstantiationException - Should never happen. If the object equality lock count manager cannot be instantiated or does not have a parameterless constructor, an InstantiationException will be thrown.
        IllegalAccessException - Should never happen. If the object equality lock count manager class or its constructor is not accessible, an IllegalAccessException will be thrown.
      • ThreadLock

        public ThreadLock​(boolean exclusive,
                          Logger logger)
                   throws InstantiationException,
                          IllegalAccessException
        Creates a new ThreadLock resembling ReentrantReadWriteLock in non-exclusive mode, that is, it is based on threads, it uses Object.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:
        InstantiationException - Should never happen. If the object equality lock count manager cannot be instantiated or does not have a parameterless constructor, an InstantiationException will be thrown.
        IllegalAccessException - Should never happen. If the object equality lock count manager class or its constructor is not accessible, an IllegalAccessException will be thrown.
      • ThreadLock

        public ThreadLock​(Class<? extends LockCountManager<Thread>> lockCountManager,
                          boolean exclusive,
                          Logger logger)
                   throws InstantiationException,
                          IllegalAccessException
        Creates a new ThreadLock using the designated lock count manager and the designated exclusive mode. This constructor is for usage by ObjectLockManager.
        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:
        InstantiationException - If the designated lock count manager class cannot be instantiated or does not have a parameterless constructor, an InstantiationException will be thrown.
        IllegalAccessException - If the designated lock count manager class or its constructor is not accessible, an IllegalAccessException will be thrown.
      • ThreadLock

        public ThreadLock​(Class<? extends LockCountManager<Thread>> lockCountManager,
                          boolean exclusive,
                          LockNotification<Thread> notification,
                          Logger logger)
                   throws InstantiationException,
                          IllegalAccessException
        Creates a new ThreadLock 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 by ObjectLockManager.
        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 is null, no notification will be sent.
        logger - The logger for log messages.
        Throws:
        InstantiationException - If the designated lock count manager class cannot be instantiated or does not have a parameterless constructor, an InstantiationException will be thrown.
        IllegalAccessException - If the designated lock count manager class or its constructor is not accessible, an IllegalAccessException will be thrown.