Class BlockingBoolean

  • All Implemented Interfaces:
    java.io.Serializable

    public class BlockingBoolean
    extends java.util.concurrent.locks.AbstractQueuedSynchronizer
    Mutable boolean that allows threads to wait for a specified value.
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.concurrent.locks.AbstractQueuedSynchronizer

        java.util.concurrent.locks.AbstractQueuedSynchronizer.ConditionObject
    • Constructor Summary

      Constructors 
      Constructor Description
      BlockingBoolean​(boolean value)
      Creates a new blocking boolean with the specified value.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void await​(boolean value)
      Causes the current thread to wait until the boolean equals the specified value unless the thread is interrupted.
      boolean await​(boolean value, long timeout, java.util.concurrent.TimeUnit unit)
      Causes the current thread to wait until the boolean equals the specified value unless the thread is interrupted, or the specified waiting time elapses.
      boolean get()
      Gets the value of the blocking boolean.
      void set​(boolean value)
      Sets the value of the blocking boolean.
      protected int tryAcquireShared​(int acquires)  
      protected boolean tryReleaseShared​(int releases)  
      • Methods inherited from class java.util.concurrent.locks.AbstractQueuedSynchronizer

        acquire, acquireInterruptibly, acquireShared, acquireSharedInterruptibly, compareAndSetState, getExclusiveQueuedThreads, getFirstQueuedThread, getQueuedThreads, getQueueLength, getSharedQueuedThreads, getState, getWaitingThreads, getWaitQueueLength, hasContended, hasQueuedPredecessors, hasQueuedThreads, hasWaiters, isHeldExclusively, isQueued, owns, release, releaseShared, setState, toString, tryAcquire, tryAcquireNanos, tryAcquireSharedNanos, tryRelease
      • Methods inherited from class java.util.concurrent.locks.AbstractOwnableSynchronizer

        getExclusiveOwnerThread, setExclusiveOwnerThread
      • Methods inherited from class java.lang.Object

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

      • BlockingBoolean

        public BlockingBoolean​(boolean value)
        Creates a new blocking boolean with the specified value.
        Parameters:
        value - the starting value
    • Method Detail

      • await

        public void await​(boolean value)
                   throws java.lang.InterruptedException
        Causes the current thread to wait until the boolean equals the specified value unless the thread is interrupted.
        Parameters:
        value - specified value
        Throws:
        java.lang.InterruptedException - if interrupted while waiting
      • await

        public boolean await​(boolean value,
                             long timeout,
                             java.util.concurrent.TimeUnit unit)
                      throws java.lang.InterruptedException
        Causes the current thread to wait until the boolean equals the specified value unless the thread is interrupted, or the specified waiting time elapses.
        Parameters:
        value - specified value
        timeout - the maximum time to wait
        unit - the time unit of the timeout argument
        Returns:
        true if the count reached zero and false if the waiting time elapsed before the count reached zero
        Throws:
        java.lang.InterruptedException - if interrupted while waiting
      • tryAcquireShared

        protected int tryAcquireShared​(int acquires)
        Overrides:
        tryAcquireShared in class java.util.concurrent.locks.AbstractQueuedSynchronizer
      • set

        public void set​(boolean value)
        Sets the value of the blocking boolean.
        Parameters:
        value - new value
      • get

        public boolean get()
        Gets the value of the blocking boolean.
        Returns:
        current value
      • tryReleaseShared

        protected boolean tryReleaseShared​(int releases)
        Overrides:
        tryReleaseShared in class java.util.concurrent.locks.AbstractQueuedSynchronizer