Class TaskManager
public class TaskManager implements Runnable
{
// Constructors
public TaskManager(ThreadGroup threadGroup);
public TaskManager(ThreadGroup threadGroup,
boolean runTasksAsDaemons);
// Methods
public synchronized boolean cancel(int id);
public static TaskManager global();
public void run();
public int schedule(Runnable runnable);
public int schedule(Runnable runnable, long when);
public synchronized int schedule(Runnable runnable, long when,
boolean lightweight);
}
This class schedules or manages the execution of runnable objects.
public TaskManager(ThreadGroup threadGroup);
Constructs a new TaskManager object.
Parameter | Description |
threadGroup
| The thread group that the task manager creates threads in.
|
public TaskManager(ThreadGroup threadGroup, boolean runTasksAsDaemons);
Constructs a new TaskManager object.
Parameter | Description |
threadGroup
| The thread group that the task manager creates threads in.
|
runTasksAsDaemons
| Set to true if the tasks in this task manager are to run on daemon threads; otherwise, set to false.
|
public synchronized boolean cancel(int id);
Cancels a pending runnable object.
Return Value:
Returns true if the runnable object was cancelled successfully; returns false if the task was already run or had never been scheduled.
Parameter | Description |
id
| An integer that identifies the task.
|
public static TaskManager global();
Retrieves the global task manager.
Return Value:
Returns the global TaskManager object.
public void run();
Called when the thread is started.
Return Value:
No return value.
public int schedule(Runnable runnable);
Schedules a runnable object to run immediately.
Return Value:
Returns a non-zero integer that identifies the task.
Parameter | Description |
runnable
| The object that is run.
|
public int schedule(Runnable runnable, long when);
Schedules a runnable object to run at a specified time.
Return Value:
Returns a non-zero integer that identifies the task.
Parameter | Description |
runnable
| The object that is run.
|
long
| The time at which the object is to start.
|
public synchronized int schedule(Runnable runnable, long when,
boolean lightweight);
Schedules a runnable object to run at a specified time.
Return Value:
Returns a non-zero integer that identifies the task.
Parameter | Description |
runnable
| The object that is run.
|
when
| The time at which the object is run.
|
lightweight
| Set to true to run the task as a lightweight task.
|