Class ResourceLock

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.AutoCloseable, java.util.concurrent.locks.Lock

    public final class ResourceLock
    extends java.util.concurrent.locks.ReentrantLock
    implements java.lang.AutoCloseable
    Extends a ReentrantLock for use in try-with-resources block.

    Example use

    
    
       try (ResourceLock ignore = lock.obtain()) {
         // do something while holding the resource lock
       }
    
     
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      ResourceLock()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Unlock on exit of try-with-resources block.
      ResourceLock obtain()
      Obtain a lock and return the ResourceLock for use in try-with-resources block.
      • Methods inherited from class java.util.concurrent.locks.ReentrantLock

        getHoldCount, getOwner, getQueuedThreads, getQueueLength, getWaitingThreads, getWaitQueueLength, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isHeldByCurrentThread, isLocked, lock, lockInterruptibly, newCondition, toString, tryLock, tryLock, unlock
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ResourceLock

        public ResourceLock()
    • Method Detail

      • obtain

        public ResourceLock obtain()
        Obtain a lock and return the ResourceLock for use in try-with-resources block.
      • close

        public void close()
        Unlock on exit of try-with-resources block.
        Specified by:
        close in interface java.lang.AutoCloseable