Class Notifier

java.lang.Object
ca.spottedleaf.concurrentutil.lock.Notifier

public final class Notifier extends Object
Synchronisation utility which may be used to park threads waiting on a single condition.
  • Constructor Details

    • Notifier

      public Notifier(boolean blocked)
  • Method Details

    • notifyThreads

      public boolean notifyThreads()
      Unblocks and unparks all waiting threads. It is guaranteed that all threads which are parked when this function is invoked are unparked.
      Returns:
      true if the blocked state was changed to false, or false if not blocked
    • notifyThreadsAndBlock

      public boolean notifyThreadsAndBlock()
      This function is equivalent to invoking notifyThreads() followed by block() except that it is atomic and possibly faster. This function is useful for causing all threads previously parked to become schedulable again while forcing new threads which enter waitUntilReady() to park.
      Returns:
      true if the blocked state is true, false otherwise
    • block

      public boolean block()
      Requires any thread entering waitUntilReady() to park until notified.
      Returns:
      false if the blocked state is already set, true if this thread set the blocked state.
    • waitUntilReady

      public void waitUntilReady()
      This function causes this thread to be parked if blocked. The thread is only unblocked when a notification arrives, such as through notifyThreads().