Class Task

java.lang.Object
com.dianxin.tori.base.scheduler.Task

public class Task extends Object
Represents a scheduled or running execution unit managed by Scheduler.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Task(boolean sync)
    Constructs a new tracked task.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Cancels this task.
    int
    Retrieves the unique identifier of this task.
    boolean
    Checks whether the task execution has been cancelled.
    boolean
    Checks whether the task execution completed, terminated with an error, or was cancelled.
    boolean
    Checks whether this task runs on the synchronous/CPU thread pool.
    protected void
    setFuture(Future<?> future)
    Attaches the underlying execution future to this task wrapper.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Task

      public Task(boolean sync)
      Constructs a new tracked task.
      Parameters:
      sync - true if dispatched to CPU pool, false if 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:
      true if scheduled on the CPU pool, false if on the I/O pool
    • isCancelled

      public boolean isCancelled()
      Checks whether the task execution has been cancelled.
      Returns:
      true if cancelled before completion
    • isDone

      public boolean isDone()
      Checks whether the task execution completed, terminated with an error, or was cancelled.
      Returns:
      true if done
    • cancel

      public void cancel()
      Cancels this task. If the task is currently active, it attempts to interrupt the worker thread.
    • setFuture

      protected void setFuture(Future<?> future)
      Attaches the underlying execution future to this task wrapper.
      Parameters:
      future - the tracked future returned by the executor