Class AutoResetEvent

java.lang.Object
com.seeq.utilities.AutoResetEvent

public class AutoResetEvent extends Object
This class is a copy of the C# AutoResetEvent class. The .NET Framework source code is not available, so behavior was determined by reading the documentation. See https://msdn.microsoft.com/en-us/library/system.threading.autoresetevent(v=vs.110).aspx for more info.
  • Constructor Summary

    Constructors
    Constructor
    Description
    AutoResetEvent(boolean initialState)
    Initializes a new instance of the AutoResetEvent class with a boolean value indicating whether to set the initial state to signaled.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Sets the state of the event to nonsignaled, causing threads to block.
    boolean
    set()
    Sets the state of the event to signaled, allowing one waiting thread to proceed.
    boolean
    Blocks the current thread until the signal is received.
    boolean
    waitOne(long timeoutMilliseconds)
    Blocks the current thread until the signal is received or the timeout is reached.
    boolean
    waitOne(Duration timeout)
    Blocks the current thread until the signal is received or the timeout is reached.

    Methods inherited from class java.lang.Object

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

    • AutoResetEvent

      public AutoResetEvent(boolean initialState)
      Initializes a new instance of the AutoResetEvent class with a boolean value indicating whether to set the initial state to signaled.
      Parameters:
      initialState - true to set the initial state to signaled; false to set the initial state to non-signaled.
  • Method Details

    • waitOne

      public boolean waitOne() throws InterruptedException
      Blocks the current thread until the signal is received.
      Returns:
      true if the current instance receives a signal. If the current instance is never signaled, waitOne() never returns.
      Throws:
      InterruptedException - thrown if thread is interrupted
    • waitOne

      public boolean waitOne(long timeoutMilliseconds) throws InterruptedException
      Blocks the current thread until the signal is received or the timeout is reached.
      Parameters:
      timeoutMilliseconds - The number of milliseconds to wait, or -1 to wait indefinitely.
      Returns:
      true if the current instance receives a signal; otherwise, false.
      Throws:
      InterruptedException - thrown if thread is interrupted
    • waitOne

      public boolean waitOne(Duration timeout) throws InterruptedException
      Blocks the current thread until the signal is received or the timeout is reached.
      Parameters:
      timeout - The duration to wait.
      Returns:
      true if the current instance receives a signal; otherwise, false.
      Throws:
      InterruptedException - thrown if thread is interrupted
    • set

      public boolean set()
      Sets the state of the event to signaled, allowing one waiting thread to proceed.
      Returns:
      true if the operation succeeds; otherwise, false.
    • reset

      public boolean reset()
      Sets the state of the event to nonsignaled, causing threads to block.
      Returns:
      true if the operation succeeds; otherwise, false.