Class SchedulerImpl

java.lang.Object
com.dianxin.tori.base.scheduler.SchedulerImpl
All Implemented Interfaces:
Scheduler

public class SchedulerImpl extends Object implements Scheduler
Default thread-safe implementation of Scheduler.

Employs a single-threaded daemon scheduled executor as an internal clock ticker to prevent thread starvation, delegating actual task computations to either ExecutorManager.cpu() or ExecutorManager.io().

  • Constructor Details

    • SchedulerImpl

      public SchedulerImpl()
      Initializes the scheduler with a dedicated daemon timer thread.
  • Method Details

    • runTask

      public Task runTask(Runnable runnable)
      Description copied from interface: Scheduler
      Executes a task immediately on the primary CPU-bound thread pool.
      Specified by:
      runTask in interface Scheduler
      Parameters:
      runnable - the task logic to execute
      Returns:
      a tracked Task instance
    • runTaskAsync

      public Task runTaskAsync(Runnable runnable)
      Description copied from interface: Scheduler
      Executes a task immediately on the asynchronous I/O-bound thread pool.
      Specified by:
      runTaskAsync in interface Scheduler
      Parameters:
      runnable - the task logic to execute
      Returns:
      a tracked Task instance
    • runTaskLater

      public Task runTaskLater(Runnable runnable, long delay, TimeUnit unit)
      Description copied from interface: Scheduler
      Schedules a task to execute after a specified delay on the CPU thread pool.
      Specified by:
      runTaskLater in interface Scheduler
      Parameters:
      runnable - the task logic to execute
      delay - the time to wait before executing
      unit - the time unit of the delay parameter
      Returns:
      a tracked Task instance
    • runTaskLaterAsync

      public Task runTaskLaterAsync(Runnable runnable, long delay, TimeUnit unit)
      Description copied from interface: Scheduler
      Schedules a task to execute asynchronously after a specified delay on the I/O thread pool.
      Specified by:
      runTaskLaterAsync in interface Scheduler
      Parameters:
      runnable - the task logic to execute
      delay - the time to wait before executing
      unit - the time unit of the delay parameter
      Returns:
      a tracked Task instance
    • runTaskTimer

      public Task runTaskTimer(Runnable runnable, long delay, long period, TimeUnit unit)
      Description copied from interface: Scheduler
      Schedules a repeated task to execute on the CPU thread pool.
      Specified by:
      runTaskTimer in interface Scheduler
      Parameters:
      runnable - the task logic to execute
      delay - the time to wait before the first execution
      period - the interval between successive executions
      unit - the time unit of the delay and period parameters
      Returns:
      a tracked Task instance
    • runTaskTimerAsync

      public Task runTaskTimerAsync(Runnable runnable, long delay, long period, TimeUnit unit)
      Description copied from interface: Scheduler
      Schedules a repeated task to execute asynchronously on the I/O thread pool.
      Specified by:
      runTaskTimerAsync in interface Scheduler
      Parameters:
      runnable - the task logic to execute
      delay - the time to wait before the first execution
      period - the interval between successive executions
      unit - the time unit of the delay and period parameters
      Returns:
      a tracked Task instance
    • cancelTask

      public void cancelTask(int taskId)
      Description copied from interface: Scheduler
      Cancels an active or scheduled task matching the unique task ID.
      Specified by:
      cancelTask in interface Scheduler
      Parameters:
      taskId - the unique identifier of the target task
    • shutdown

      public void shutdown()
      Description copied from interface: Scheduler
      Cancels all currently scheduled tasks and releases underlying thread pool resources.
      Specified by:
      shutdown in interface Scheduler