public class TaskScheduler
extends java.lang.Object
TaskScheduler
keeps a collection of Runnable
objects, and calls all of
their run()
methods sequentially and continuously.Modifier and Type | Class and Description |
---|---|
private class |
TaskScheduler.TaskSchedulerThread
A
TaskSchedulerThread is a Thread that is used to run all of the
registered tasks. |
Modifier and Type | Field and Description |
---|---|
private java.util.List<java.lang.Runnable> |
tasks
The list of
Runnable objects that should be executed. |
private java.lang.Thread |
taskThread
The
Thread to use for executing the registered tasks. |
Constructor and Description |
---|
TaskScheduler()
Constructs a new
TaskScheduler . |
Modifier and Type | Method and Description |
---|---|
void |
registerTask(java.lang.Runnable task)
Adds a given
Runnable to be executed in the cycle. |
void |
removeTask(java.lang.Runnable task)
Removes a given
Runnable from the cycle. |
private void |
runAllTasks()
Calls the
run() method of all Runnable objects that have been
registered with this task scheduler. |
private volatile java.util.List<java.lang.Runnable> tasks
Runnable
objects that should be executed.private java.lang.Thread taskThread
Thread
to use for executing the registered tasks.public void registerTask(java.lang.Runnable task)
Runnable
to be executed in the cycle.task
- the task to be executed in the cycle.public void removeTask(java.lang.Runnable task)
Runnable
from the cycle.task
- the task to be deleted from the cycle.private void runAllTasks()
run()
method of all Runnable
objects that have been
registered with this task scheduler.