Package com.dianxin.tori.base.scheduler
Class Task
java.lang.Object
com.dianxin.tori.base.scheduler.Task
Represents a scheduled or running execution unit managed by
Scheduler.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancels this task.intRetrieves the unique identifier of this task.booleanChecks whether the task execution has been cancelled.booleanisDone()Checks whether the task execution completed, terminated with an error, or was cancelled.booleanisSync()Checks whether this task runs on the synchronous/CPU thread pool.protected voidAttaches the underlying execution future to this task wrapper.
-
Constructor Details
-
Task
public Task(boolean sync) Constructs a new tracked task.- Parameters:
sync-trueif dispatched to CPU pool,falseif dispatched to I/O pool
-
-
Method Details
-
getTaskId
public int getTaskId()Retrieves the unique identifier of this task.- Returns:
- the task ID
-
isSync
public boolean isSync()Checks whether this task runs on the synchronous/CPU thread pool.- Returns:
trueif scheduled on the CPU pool,falseif on the I/O pool
-
isCancelled
public boolean isCancelled()Checks whether the task execution has been cancelled.- Returns:
trueif cancelled before completion
-
isDone
public boolean isDone()Checks whether the task execution completed, terminated with an error, or was cancelled.- Returns:
trueif done
-
cancel
public void cancel()Cancels this task. If the task is currently active, it attempts to interrupt the worker thread. -
setFuture
Attaches the underlying execution future to this task wrapper.- Parameters:
future- the tracked future returned by the executor
-