|
Bali Share 1.1.18 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--oracle.bali.share.thread.TaskScheduler
The TaskScheduler object provides a single object on which multiple tasks may be scheduled. Tasks are objects that implement the simple Task interface.
In the past, clients may have created multiple Timers for each task they needed to execute. However, since each Timer creates its own thread, this got to be extremely expensive. TaskSchedulers avoid this problem by using a single thread for all tasks.
By default, all tasks are executed in the same thread, so any particularly lengthy tasks can delay all subsequent tasks. Clients who need to execute expensive tasks, but don't want to block other tasks from running should use the SpawningTaskScheduler subclass or manually create their own Threads within their tasks.
Task
,
Timer
Constructor Summary | |
TaskScheduler()
Creates a TaskScheduler. |
Method Summary | |
void |
addSchedulerListener(SchedulerListener listener)
Adds a listener for scheduler events. |
void |
cancel(Task task)
Removes the given task from the scheduler. |
protected void |
finalize()
Cleans up the task scheduler. |
static TaskScheduler |
getDefaultTaskScheduler()
Returns a default task scheduler. |
java.lang.String |
getName()
Gets the name of the scheduler. |
int |
getPriority()
Returns the priority of the scheduler. |
boolean |
isDaemon()
Tests if this scheduler is a daemon scheduler. |
protected void |
processSchedulerEvent(SchedulerEvent event)
Processes a single scheduler event. |
protected void |
processTask(Task task,
long time)
Processes a task. |
void |
removeSchedulerListener(SchedulerListener listener)
Removes a listener for scheduler events. |
protected void |
runTask(Task task,
TaskEvent event)
Executes a task. |
void |
schedule(Task task,
int delay)
Queues a task with a given delay. |
void |
setDaemon(boolean isDaemon)
Marks this scheduler as either a daemon scheduler or a user scheduler. |
void |
setName(java.lang.String name)
Sets the name of the scheduler, used by any threads created by the scheduler. |
void |
setPriority(int priority)
Sets the scheduler's priority. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public TaskScheduler()
Method Detail |
public static TaskScheduler getDefaultTaskScheduler()
Clients can use this task scheduler for scheduling their own tasks, but should be careful not to overload it with too many tasks or any potentially time-consuming tasks, since any such tasks will block some EWT functions from proceeding.
Clients with expensive tasks or many tasks should usually create their own task scheduler for all of their needs.
public void schedule(Task task, int delay)
Tasks can be scheduled with a delay of zero milliseconds. In general, this will schedule the task to be delivered as soon as possible, though after any currently scheduled tasks that are overdue.
task
- an object implementing the Task interface.delay
- the number of milliseconds before the task will
executepublic void cancel(Task task)
public void setDaemon(boolean isDaemon)
This method must be called before any tasks have been scheduled, or an IllegalThreadStateException will be thrown.
isDaemon
- if true, marks this scheduler as a daemon schedulerIllegalThreadStateException
- if any tasks have been scheduledpublic boolean isDaemon()
public void setName(java.lang.String name)
public java.lang.String getName()
public void setPriority(int priority)
public int getPriority()
public void addSchedulerListener(SchedulerListener listener)
listener
- the listenerpublic void removeSchedulerListener(SchedulerListener listener)
listener
- the listenerprotected void processTask(Task task, long time)
task
- the task to executetime
- the absolute time, in milliseconds, when task expected
to be executed.runTask(oracle.bali.share.thread.Task, oracle.bali.share.thread.TaskEvent)
protected void runTask(Task task, TaskEvent event)
task
- the task to executeevent
- the task event to deliver to the taskprotected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- Any exception thrown by a finalize method causes
finalization to halt; otherwise, it is ignored.protected void processSchedulerEvent(SchedulerEvent event)
event
- the scheduler event to process
|
Bali Share 1.1.18 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |