Class AutoLock

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.AutoCloseable
    Direct Known Subclasses:
    AutoLock.WithCondition

    public class AutoLock
    extends java.lang.Object
    implements java.lang.AutoCloseable, java.io.Serializable

    Reentrant lock that can be used in a try-with-resources statement.

    Typical usage:

     try (AutoLock lock = this.lock.lock())
     {
         // Something
     }
     
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  AutoLock.WithCondition
      A reentrant lock with a condition that can be used in a try-with-resources statement.
    • Constructor Summary

      Constructors 
      Constructor Description
      AutoLock()  
    • Constructor Detail

      • AutoLock

        public AutoLock()
    • Method Detail

      • lock

        public AutoLock lock()

        Acquires the lock.

        Returns:
        this AutoLock for unlocking
      • isHeldByCurrentThread

        public boolean isHeldByCurrentThread()
        Returns:
        whether this lock is held by the current thread
        See Also:
        ReentrantLock.isHeldByCurrentThread()
      • newCondition

        public java.util.concurrent.locks.Condition newCondition()
        Returns:
        a Condition associated with this lock
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable