Class SingleWaiterMultiNotifier

  • All Implemented Interfaces:
    Notifier
    Direct Known Subclasses:
    SingleWaiterCooperativeNotifier

    public class SingleWaiterMultiNotifier
    extends Object
    implements Notifier
    A Condition-like object, used by a single thread to block for a notification, and optimized for many concurrent notifications by other threads. Basically, this is a blocking queue without any state to actually enqueue: the Notifier.await() method is analogous to an imaginary "take all" variant of the BlockingQueue.take() method, and the signal() method is analogous to BlockingQueue.put().

    Note that no synchronization is needed to use this class; i.e. clients must not synchronize on this class prior to calling await() or signal(), nor should the use any of the primitive wait() or notify() methods.

    Since SingleWaiterMultiNotifier is only usable by a single waiting thread it is does not require an external readiness check, as signaling can record that state.

    Author:
    cp/mf 2010-06-15
    • Field Detail

      • m_oState

        protected volatile Object m_oState
        The signaling state, null for unsignaled, this for signaled, or a thread for the single awaiting thread
    • Constructor Detail

      • SingleWaiterMultiNotifier

        public SingleWaiterMultiNotifier()
    • Method Detail

      • await

        public void await​(long cMillis)
                   throws InterruptedException
        Description copied from interface: Notifier
        Wait for a notification. Note that spurious wake-ups are possible.
        Specified by:
        await in interface Notifier
        Parameters:
        cMillis - the maximum wait time in milliseconds, or zero for indefinite
        Throws:
        InterruptedException - if the calling thread is interrupted while it is waiting
      • signal

        public void signal()
        Description copied from interface: Notifier
        Notifies the waiting thread(s), waking them up if awaiting.
        Specified by:
        signal in interface Notifier
      • getWaitingThread

        public Thread getWaitingThread()
        Return the thread which is waiting on this notifier.
        Returns:
        the waiting thread or null
      • signalInternal

        protected Thread signalInternal()
        Signal the notifier returning any thread which needs to be unparked.
        Returns:
        a the thread if any which needs to be unparked.
      • consumeSignal

        protected void consumeSignal()
        Consume the signal.