Class CondVar


  • public class CondVar
    extends java.lang.Object
    A condition variable with methods for (timed) waiting and signalling
    Since:
    3.6
    Author:
    Bela Ban
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.locks.Condition cond  
      protected java.util.concurrent.locks.Lock lock  
    • Constructor Summary

      Constructors 
      Constructor Description
      CondVar()  
      CondVar​(java.util.concurrent.locks.Lock lock)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void signal​(boolean signal_all)
      Wakes up one (signal_all=false) or all (signal_all=true) blocked threads.
      void waitFor​(java.util.function.BooleanSupplier condition)
      Blocks until condition is true.
      boolean waitFor​(java.util.function.BooleanSupplier condition, long timeout, java.util.concurrent.TimeUnit unit)
      Blocks until condition is true or the time elapsed
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • lock

        protected final java.util.concurrent.locks.Lock lock
      • cond

        protected final java.util.concurrent.locks.Condition cond
    • Constructor Detail

      • CondVar

        public CondVar()
      • CondVar

        public CondVar​(java.util.concurrent.locks.Lock lock)
    • Method Detail

      • waitFor

        public void waitFor​(java.util.function.BooleanSupplier condition)
        Blocks until condition is true.
        Parameters:
        condition - The condition. Must be non-null
      • waitFor

        public boolean waitFor​(java.util.function.BooleanSupplier condition,
                               long timeout,
                               java.util.concurrent.TimeUnit unit)
        Blocks until condition is true or the time elapsed
        Parameters:
        condition - The condition
        timeout - The timeout to wait. A value <= 0 causes immediate return
        unit - TimeUnit
        Returns:
        The condition's status
      • signal

        public void signal​(boolean signal_all)
        Wakes up one (signal_all=false) or all (signal_all=true) blocked threads. Usually called when the condition changed to true.
        Parameters:
        signal_all -