Class ThreadGate


  • public class ThreadGate
    extends java.lang.Object
    This class implements a simple one-shot gate for threads. The gate starts closed and will block any threads that try to wait on it. Once opened, all waiting threads will be released. The gate cannot be reused.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean m_initialized  
      private java.lang.Object m_msg  
      private boolean m_open  
    • Constructor Summary

      Constructors 
      Constructor Description
      ThreadGate()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean await​(long timeout)
      Wait for the gate to open.
      java.lang.Object getMessage()
      Returns the message object associated with the gate; the message is just an arbitrary object used to pass information to the waiting threads.
      void open()
      Open the gate and release any waiting threads.
      void setMessage​(java.lang.Object msg)
      Sets the message object associated with the gate.
      • Methods inherited from class java.lang.Object

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

      • m_open

        private boolean m_open
      • m_msg

        private java.lang.Object m_msg
      • m_initialized

        private boolean m_initialized
    • Constructor Detail

      • ThreadGate

        public ThreadGate()
    • Method Detail

      • open

        public void open()
        Open the gate and release any waiting threads.
      • getMessage

        public java.lang.Object getMessage()
        Returns the message object associated with the gate; the message is just an arbitrary object used to pass information to the waiting threads.
        Returns:
        the message object associated with the gate.
      • setMessage

        public void setMessage​(java.lang.Object msg)
        Sets the message object associated with the gate. The message object can only be set once, subsequent calls to this method are ignored.
        Parameters:
        msg - the message object to associate with this gate.
      • await

        public boolean await​(long timeout)
                      throws java.lang.InterruptedException
        Wait for the gate to open.
        Returns:
        true if the gate was opened or false if the timeout expired.
        Throws:
        java.lang.InterruptedException - If the calling thread is interrupted; the gate still remains closed until opened.