Interface Barrier


@Internal public interface Barrier
The barrier allows us to hold up an operation for a short while. This class is not API and should only be used for testing.

Barriers must be lowered in a finally block so as to avoid blocking operations forever.

Since:
v5.2
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Blocks the calling thread until the barrier is lowered or the calling thread is interrupted.
    void
    Lowers the barrier.
    void
    Lower the barrier to allow waiting threads through, then immediately raise it again.
    Returns this barrier's name.
    void
    Raises the barrier.
  • Method Details

    • name

      String name()
      Returns this barrier's name.
      Returns:
      a String containing the barrier's name
    • await

      void await()
      Blocks the calling thread until the barrier is lowered or the calling thread is interrupted. Callers may use Thread.isInterrupted() to check if the thread has been interrupted.
    • raise

      void raise()
      Raises the barrier. Threads that call await() when the barrier is raised will block indefinitely until the barrier is lowered again.
    • lower

      void lower()
      Lowers the barrier. Any threads that are blocked on await() will no longer be blocked.
    • lowerThenRaise

      void lowerThenRaise()
      Lower the barrier to allow waiting threads through, then immediately raise it again. Waiting threads are only allowed through once. This is useful for stepping through loops containing a barrier.