Class LockManager


  • public class LockManager
    extends Object
    Manages a set of active locks. If any active lock is garbage collected it is automatically removed from the set and logged.
    Author:
    James Leigh
    • Constructor Detail

      • LockManager

        public LockManager()
        Create a new set of locks.
      • LockManager

        public LockManager​(boolean trackLocks)
        Creates a new set of locks, optionally with lock tracking enabled.
        Parameters:
        trackLocks - Controls whether to keep a stack trace of active locks. Enabling lock tracking will add some overhead, but can be very useful for debugging.
      • LockManager

        public LockManager​(boolean trackLocks,
                           int collectionFrequency)
        Creates a new set of locks, optionally with lock tracking enabled.
        Parameters:
        trackLocks - Controls whether to keep a stack trace of active locks. Enabling lock tracking will add some overhead, but can be very useful for debugging.
        collectionFrequency - Number of milliseconds to block the first thread, waiting for active locks to finish, before running the memory garbage collection, to free abandoned active locks.
    • Method Detail

      • isActiveLock

        public boolean isActiveLock()
        If any locks in this collection that are still active.
        Returns:
        true of one or more locks that have not be released.
      • waitForActiveLocks

        public void waitForActiveLocks()
                                throws InterruptedException
        Blocks current thread until the number of active locks has reached zero.
        Throws:
        InterruptedException - if any thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.
      • createLock

        public Lock createLock​(String alias)
        Creates a new active lock. This increases the number of active locks until its Lock.release() method is called, which decreases the number of active locks by the same amount.
        Parameters:
        alias - a short string used to log abandon locks
        Returns:
        an active lock