Class AutoLock.WithCondition

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.AutoCloseable
    Enclosing class:
    AutoLock

    public static class AutoLock.WithCondition
    extends AutoLock
    A reentrant lock with a condition that can be used in a try-with-resources statement.

    Typical usage:

     // Waiting
     try (AutoLock lock = _lock.lock())
     {
         lock.await();
     }
    
     // Signaling
     try (AutoLock lock = _lock.lock())
     {
         lock.signalAll();
     }
     
    See Also:
    Serialized Form
    • Constructor Detail

      • WithCondition

        public WithCondition()
    • Method Detail

      • signal

        public void signal()
        See Also:
        Condition.signal()
      • signalAll

        public void signalAll()
        See Also:
        Condition.signalAll()
      • await

        public void await()
                   throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException - if the current thread is interrupted
        See Also:
        Condition.await()
      • await

        public boolean await​(long time,
                             java.util.concurrent.TimeUnit unit)
                      throws java.lang.InterruptedException
        Parameters:
        time - the time to wait
        unit - the time unit
        Returns:
        false if the waiting time elapsed
        Throws:
        java.lang.InterruptedException - if the current thread is interrupted
        See Also:
        Condition.await(long, TimeUnit)