public final class PriorityTaskManager
extends java.lang.Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
PriorityTaskManager.PriorityTooLowException
Thrown when task attempts to proceed when another registered task has a higher priority.
|
Constructor and Description |
---|
PriorityTaskManager() |
Modifier and Type | Method and Description |
---|---|
void |
add(int priority)
Register a new task.
|
void |
proceed(int priority)
Blocks until the task is allowed to proceed.
|
boolean |
proceedNonBlocking(int priority)
A non-blocking variant of
proceed(int) . |
void |
proceedOrThrow(int priority)
A throwing variant of
proceed(int) . |
void |
remove(int priority)
Unregister a task.
|
public void add(int priority)
remove(int)
when done.priority
- The priority of the task. Larger values indicate higher priorities.public void proceed(int priority) throws java.lang.InterruptedException
priority
- The priority of the task.java.lang.InterruptedException
- If the thread is interrupted.public boolean proceedNonBlocking(int priority)
proceed(int)
.priority
- The priority of the task.public void proceedOrThrow(int priority) throws PriorityTaskManager.PriorityTooLowException
proceed(int)
.priority
- The priority of the task.PriorityTaskManager.PriorityTooLowException
- If the task is not allowed to proceed.public void remove(int priority)
priority
- The priority of the task.