Class ResourceLock

All Implemented Interfaces:
Serializable, AutoCloseable, Lock

public final class ResourceLock extends ReentrantLock implements 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:
  • Constructor Details

    • ResourceLock

      public ResourceLock()
  • Method Details

    • 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 AutoCloseable