Class ConcurrentNotifier

java.lang.Object
com.oracle.coherence.common.base.ConcurrentNotifier
All Implemented Interfaces:
Notifier

public abstract class ConcurrentNotifier extends Object implements Notifier
A Condition-like object, usable by multiple threads to both wait and signal.

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.

Unlike the SingleWaiterMultiNotifier, this notifier implementation requires the notion of a ready check. When the notifier is ready then a call to await because a no-op. An example ready check for a notifier based queue removal would be !queue.isEmpty();

Author:
mf 2018.04.13
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static final class 
    A link in a stack of waiting threads.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Object
    The head of a stack of waiting threads.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    await(long cMillis)
    Wait for a notification.
    protected abstract boolean
    Return true if the notifier is ready, i.e. threads entering await cant return without blocking.
    makeSelfLink(Thread threadThis, long lBitThis, Object oHead)
    Make a link for the calling thread, checking if one already exists for this notifier.
    protected void
    park(long cMillis)
    Block the calling thread if the notifier is not ready.
    void
    Notifies the waiting thread(s), waking them up if awaiting.
    protected void
    Full version of signal.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.oracle.coherence.common.base.Notifier

    await
  • Field Details

    • m_oWaitHead

      protected volatile Object m_oWaitHead
      The head of a stack of waiting threads. The head can be either a Thread, or a Link.
  • Constructor Details

    • ConcurrentNotifier

      public ConcurrentNotifier()
  • Method Details

    • 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
    • signalInternal

      protected void signalInternal()
      Full version of signal.
    • park

      protected void park(long cMillis) throws InterruptedException
      Block the calling thread if the notifier is not ready.
      Parameters:
      cMillis - the time to block for
      Throws:
      InterruptedException - if the calling thread is interrupted
    • makeSelfLink

      protected ConcurrentNotifier.Link makeSelfLink(Thread threadThis, long lBitThis, Object oHead)
      Make a link for the calling thread, checking if one already exists for this notifier.
      Parameters:
      threadThis - the calling thread
      lBitThis - this thread's contribution to the bloom filter
      oHead - the current head
      Returns:
      this thread's link, or null if we should not block
    • isReady

      protected abstract boolean isReady()
      Return true if the notifier is ready, i.e. threads entering await cant return without blocking.
      Returns:
      true if the notifier is ready