Class PrioritisedThreadPool.ExecutorGroup.ThreadPoolExecutor
java.lang.Object
ca.spottedleaf.concurrentutil.executor.thread.PrioritisedThreadPool.ExecutorGroup.ThreadPoolExecutor
- All Implemented Interfaces:
PrioritisedExecutor
- Enclosing class:
PrioritisedThreadPool.ExecutorGroup
public final class PrioritisedThreadPool.ExecutorGroup.ThreadPoolExecutor
extends Object
implements PrioritisedExecutor
-
Nested Class Summary
Nested classes/interfaces inherited from interface ca.spottedleaf.concurrentutil.executor.PrioritisedExecutor
PrioritisedExecutor.PrioritisedTask -
Method Summary
Modifier and TypeMethodDescriptioncreateTask(Runnable task) Creates, but does not queue or execute, a task atPriority.NORMALpriority.createTask(Runnable task, Priority priority) Creates, but does not queue or execute, a task atPriority.NORMALpriority.createTask(Runnable task, Priority priority, long subOrder) Creates, but does not queue or execute, a task atPriority.NORMALpriority.booleanExecutes the next available task.longGenerates the next suborder id.longReturns the number of tasks that have been executed.longReturns the number of tasks that have been scheduled are pending to be scheduled.voidhalt()Removes this queue from the thread pool without shutting the queue down or waiting for queued tasks to be executedbooleanisActive()Returns whether this executor is scheduled to run tasks or is running tasks, otherwise it returns whether this queue is not halted and not shutdown.booleanReturns whether this executor has shut down.Queues or executes a task atPriority.NORMALpriority.Queues or executes a task.Queues or executes a task.voidsetMaxParallelism(int maxParallelism) booleanshutdown()Prevent further additions to this executor.
-
Method Details
-
halt
public void halt()Removes this queue from the thread pool without shutting the queue down or waiting for queued tasks to be executed -
isActive
public boolean isActive()Returns whether this executor is scheduled to run tasks or is running tasks, otherwise it returns whether this queue is not halted and not shutdown. -
shutdown
public boolean shutdown()Description copied from interface:PrioritisedExecutorPrevent further additions to this executor. Attempts to add after this call has completed (potentially during) will result inIllegalStateExceptionbeing thrown.This operation is atomic with respect to other shutdown calls
After this call has completed, regardless of return value, this executor will be shutdown.
- Specified by:
shutdownin interfacePrioritisedExecutor- Returns:
trueif the executor was shutdown,falseif it has shut down already- See Also:
-
isShutdown
public boolean isShutdown()Description copied from interface:PrioritisedExecutorReturns whether this executor has shut down. Effectively, returns whether new tasks will be rejected. This method does not indicate whether all the tasks scheduled have been executed.- Specified by:
isShutdownin interfacePrioritisedExecutor- Returns:
- Returns whether this executor has shut down.
-
setMaxParallelism
public void setMaxParallelism(int maxParallelism) -
getTotalTasksScheduled
public long getTotalTasksScheduled()Description copied from interface:PrioritisedExecutorReturns the number of tasks that have been scheduled are pending to be scheduled.- Specified by:
getTotalTasksScheduledin interfacePrioritisedExecutor
-
getTotalTasksExecuted
public long getTotalTasksExecuted()Description copied from interface:PrioritisedExecutorReturns the number of tasks that have been executed.- Specified by:
getTotalTasksExecutedin interfacePrioritisedExecutor
-
generateNextSubOrder
public long generateNextSubOrder()Description copied from interface:PrioritisedExecutorGenerates the next suborder id.- Specified by:
generateNextSubOrderin interfacePrioritisedExecutor- Returns:
- The next suborder id.
-
executeTask
public boolean executeTask()Description copied from interface:PrioritisedExecutorExecutes the next available task.If there is a task with priority
Priority.BLOCKINGavailable, then that such task is executed.If there is a task with priority
Priority.IDLEavailable then that task is only executed when there are no other tasks available with a higher priority.If there are no tasks that have priority
Priority.BLOCKINGorPriority.IDLE, then this function will be biased to execute tasks that have higher priorities.- Specified by:
executeTaskin interfacePrioritisedExecutor- Returns:
trueif a task was executed,falseotherwise
-
queueTask
Description copied from interface:PrioritisedExecutorQueues or executes a task atPriority.NORMALpriority.- Specified by:
queueTaskin interfacePrioritisedExecutor- Parameters:
task- The task to run.- Returns:
nullif the current thread immediately executed the task, else returns the prioritised task associated with the parameter
-
queueTask
Description copied from interface:PrioritisedExecutorQueues or executes a task.- Specified by:
queueTaskin interfacePrioritisedExecutor- Parameters:
task- The task to run.priority- The priority for the task.- Returns:
nullif the current thread immediately executed the task, else returns the prioritised task associated with the parameter
-
queueTask
public PrioritisedExecutor.PrioritisedTask queueTask(Runnable task, Priority priority, long subOrder) Description copied from interface:PrioritisedExecutorQueues or executes a task.- Specified by:
queueTaskin interfacePrioritisedExecutor- Parameters:
task- The task to run.priority- The priority for the task.subOrder- The task's suborder.- Returns:
nullif the current thread immediately executed the task, else returns the prioritised task associated with the parameter
-
createTask
Description copied from interface:PrioritisedExecutorCreates, but does not queue or execute, a task atPriority.NORMALpriority.- Specified by:
createTaskin interfacePrioritisedExecutor- Parameters:
task- The task to run.- Returns:
nullif the current thread immediately executed the task, else returns the prioritised task associated with the parameter
-
createTask
Description copied from interface:PrioritisedExecutorCreates, but does not queue or execute, a task atPriority.NORMALpriority.- Specified by:
createTaskin interfacePrioritisedExecutor- Parameters:
task- The task to run.priority- The priority for the task.- Returns:
nullif the current thread immediately executed the task, else returns the prioritised task associated with the parameter
-
createTask
public PrioritisedExecutor.PrioritisedTask createTask(Runnable task, Priority priority, long subOrder) Description copied from interface:PrioritisedExecutorCreates, but does not queue or execute, a task atPriority.NORMALpriority.- Specified by:
createTaskin interfacePrioritisedExecutor- Parameters:
task- The task to run.priority- The priority for the task.subOrder- The task's suborder.- Returns:
nullif the current thread immediately executed the task, else returns the prioritised task associated with the parameter
-