Class Signal


  • public class Signal
    extends java.lang.Object
    Represents a flag which can be set or waited for. Once signalled, threads waiting for it unblock or will not be blocked if started to wait when flag is already set.
    • Constructor Summary

      Constructors 
      Constructor Description
      Signal()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearSignal()
      Clear the signal - doesn't notify, as nothing should be waiting for this, even if they are they're waiting for it to go true
      boolean isSignalled()
      Peek at the signal
      void signal()
      Set the done flag
      void waitForSignal()
      Wait indefinitely for the done signal
      boolean waitForSignal​(long timeoutMs)
      Wait up to timeout for the signal
      boolean waitForSignal​(long timeout, java.time.temporal.TemporalUnit timeUnit)
      Wait up to timeout for the signal
      boolean waitForSignal​(long timeout, java.util.concurrent.TimeUnit timeUnit)
      Wait up to timeout for the signal
      boolean waitForSignal​(java.time.Duration timeout)
      Wait up to timeout for the signal
      • Methods inherited from class java.lang.Object

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

      • Signal

        public Signal()
    • Method Detail

      • signal

        public void signal()
        Set the done flag
      • clearSignal

        public void clearSignal()
        Clear the signal - doesn't notify, as nothing should be waiting for this, even if they are they're waiting for it to go true
      • waitForSignal

        public boolean waitForSignal​(long timeout,
                                     java.util.concurrent.TimeUnit timeUnit)
                              throws java.lang.InterruptedException
        Wait up to timeout for the signal
        Parameters:
        timeout - timeout
        timeUnit - unit for timeout
        Returns:
        true if signaled, false if returned by timeout
        Throws:
        java.lang.InterruptedException - on interruption of awaiting thread
      • waitForSignal

        public boolean waitForSignal​(long timeout,
                                     java.time.temporal.TemporalUnit timeUnit)
                              throws java.lang.InterruptedException
        Wait up to timeout for the signal
        Parameters:
        timeout - timeout
        timeUnit - unit for timeout
        Returns:
        true if signaled, false if returned by timeout
        Throws:
        java.lang.InterruptedException - on interruption of awaiting thread
      • waitForSignal

        public boolean waitForSignal​(java.time.Duration timeout)
                              throws java.lang.InterruptedException
        Wait up to timeout for the signal
        Parameters:
        timeout - timeout
        Returns:
        true if signaled, false if returned by timeout
        Throws:
        java.lang.InterruptedException - on interruption of awaiting thread
      • waitForSignal

        public boolean waitForSignal​(long timeoutMs)
                              throws java.lang.InterruptedException
        Wait up to timeout for the signal
        Parameters:
        timeoutMs - timeout in milliseconds
        Returns:
        true if signaled, false if returned by timeout
        Throws:
        java.lang.InterruptedException - on interruption of awaiting thread
      • waitForSignal

        public void waitForSignal()
                           throws java.lang.InterruptedException
        Wait indefinitely for the done signal
        Throws:
        java.lang.InterruptedException - on interruption of awaiting thread
      • isSignalled

        public boolean isSignalled()
        Peek at the signal
        Returns:
        the state of the signal