Class NamedLocks<T>

  • Type Parameters:
    T - the name type, required to be effectively immutable where T.hashCode() and T.equals() is concerned

    public final class NamedLocks<T>
    extends Object
    Manages multiple ReentrantLocks identified by a unique name.

    Example of use of lock():

         NamedLocks<String> locks;
         String lockName;
    
         try (Acquired lock = locks.Acquire(lockName)) {
              // locked region
         }
    
         // lock released
     

    Example of use of tryLock():

         NamedLocks<String> locks;
         String lockName;
    
         try (AcquireResult lock = locks.tryAcquire(lockName)) {
             // maybe locked region
    
             if (lock.wasAcquired()) {
                 // locked region
             } else {
                 // unlocked region
             }
         });
    
         // lock released
     
    Author:
    Robert Varga