Class PriorityTaskManager


  • public final class PriorityTaskManager
    extends Object
    Allows tasks with associated priorities to control how they proceed relative to one another.

    A task should call add(int) to register with the manager and remove(int) to unregister. A registered task will prevent tasks of lower priority from proceeding, and should call proceed(int), proceedNonBlocking(int) or proceedOrThrow(int) each time it wishes to check whether it is itself allowed to proceed.

    • Constructor Detail

      • PriorityTaskManager

        public PriorityTaskManager()
    • Method Detail

      • add

        public void add​(int priority)
        Register a new task. The task must call remove(int) when done.
        Parameters:
        priority - The priority of the task. Larger values indicate higher priorities.
      • proceed

        public void proceed​(int priority)
                     throws InterruptedException
        Blocks until the task is allowed to proceed.
        Parameters:
        priority - The priority of the task.
        Throws:
        InterruptedException - If the thread is interrupted.
      • proceedNonBlocking

        public boolean proceedNonBlocking​(int priority)
        A non-blocking variant of proceed(int).
        Parameters:
        priority - The priority of the task.
        Returns:
        Whether the task is allowed to proceed.
      • remove

        public void remove​(int priority)
        Unregister a task.
        Parameters:
        priority - The priority of the task.