Package com.dianxin.tori.base.scheduler
Class SchedulerImpl
java.lang.Object
com.dianxin.tori.base.scheduler.SchedulerImpl
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionInitializes the scheduler with a dedicated daemon timer thread. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancelTask(int taskId) Cancels an active or scheduled task matching the unique task ID.Executes a task immediately on the primary CPU-bound thread pool.runTaskAsync(Runnable runnable) Executes a task immediately on the asynchronous I/O-bound thread pool.runTaskLater(Runnable runnable, long delay, TimeUnit unit) Schedules a task to execute after a specified delay on the CPU thread pool.runTaskLaterAsync(Runnable runnable, long delay, TimeUnit unit) Schedules a task to execute asynchronously after a specified delay on the I/O thread pool.runTaskTimer(Runnable runnable, long delay, long period, TimeUnit unit) Schedules a repeated task to execute on the CPU thread pool.runTaskTimerAsync(Runnable runnable, long delay, long period, TimeUnit unit) Schedules a repeated task to execute asynchronously on the I/O thread pool.voidshutdown()Cancels all currently scheduled tasks and releases underlying thread pool resources.
-
Constructor Details
-
SchedulerImpl
public SchedulerImpl()Initializes the scheduler with a dedicated daemon timer thread.
-
-
Method Details
-
runTask
Description copied from interface:SchedulerExecutes a task immediately on the primary CPU-bound thread pool. -
runTaskAsync
Description copied from interface:SchedulerExecutes a task immediately on the asynchronous I/O-bound thread pool.- Specified by:
runTaskAsyncin interfaceScheduler- Parameters:
runnable- the task logic to execute- Returns:
- a tracked
Taskinstance
-
runTaskLater
Description copied from interface:SchedulerSchedules a task to execute after a specified delay on the CPU thread pool.- Specified by:
runTaskLaterin interfaceScheduler- Parameters:
runnable- the task logic to executedelay- the time to wait before executingunit- the time unit of the delay parameter- Returns:
- a tracked
Taskinstance
-
runTaskLaterAsync
Description copied from interface:SchedulerSchedules a task to execute asynchronously after a specified delay on the I/O thread pool.- Specified by:
runTaskLaterAsyncin interfaceScheduler- Parameters:
runnable- the task logic to executedelay- the time to wait before executingunit- the time unit of the delay parameter- Returns:
- a tracked
Taskinstance
-
runTaskTimer
Description copied from interface:SchedulerSchedules a repeated task to execute on the CPU thread pool.- Specified by:
runTaskTimerin interfaceScheduler- Parameters:
runnable- the task logic to executedelay- the time to wait before the first executionperiod- the interval between successive executionsunit- the time unit of the delay and period parameters- Returns:
- a tracked
Taskinstance
-
runTaskTimerAsync
Description copied from interface:SchedulerSchedules a repeated task to execute asynchronously on the I/O thread pool.- Specified by:
runTaskTimerAsyncin interfaceScheduler- Parameters:
runnable- the task logic to executedelay- the time to wait before the first executionperiod- the interval between successive executionsunit- the time unit of the delay and period parameters- Returns:
- a tracked
Taskinstance
-
cancelTask
public void cancelTask(int taskId) Description copied from interface:SchedulerCancels an active or scheduled task matching the unique task ID.- Specified by:
cancelTaskin interfaceScheduler- Parameters:
taskId- the unique identifier of the target task
-
shutdown
public void shutdown()Description copied from interface:SchedulerCancels all currently scheduled tasks and releases underlying thread pool resources.
-