|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--quicktime.app.time.TaskThread
The TaskThread class maintains a table of Taskable objects that will periodically have their task method called. Each time an instance of this class is created a new thread is spawned when the start method of the TaskThread object is called. The thread is stopped when the stop method is called. Taskable objects can be added or removed from TaskThreads at the applications discretion.
When the thread is running it calls its Taskable member's task method. When it has completed a single iteration of its members it will sleep for the specified sleepTime and then go through the process again until the thread is stopped.
A TaskThread object must be explicitly started - just adding a Taskable object to the collection is not sufficient to start the thread. However, once all of the Taskable objects are removed from the collection the thread will stop. To ensure that adding a Taskable object to a TaskThread will also have the thread started the addAndStart method can be used.
If a member's task() method throws an Exception it is uncerimoniously removed from the TaskThread collection - no notification is given of such an occurance.
Constructor Summary | |
TaskThread(java.lang.String tName)
Creates a TaskThread object. |
|
TaskThread(java.lang.String tName,
int sleepTime)
Creates a TaskThread object. |
Method Summary | |
void |
addAndStart(Taskable t)
This method will add a taskable client to the list. |
boolean |
addMember(java.lang.Object member)
This method will add a taskable client to the list. |
protected void |
finalize()
|
int |
getPriority()
Returns the current priority of the task thread. |
int |
getSleepTime()
The time that the thread will sleep. |
boolean |
hasMember(java.lang.Object object)
Return true if the Taskable object is currently a member of the task list. |
boolean |
isAlive()
Returns the alive state of the thread. |
boolean |
isAppropriate(java.lang.Object object)
Returns true if the object is an instance of the Taskable interface. |
boolean |
isEmpty()
Returns true if there are no Taskable objects in the collection |
static void |
killAllThreads()
|
java.util.Enumeration |
members()
Returns an Enumeration for the current Taskable members of the collection. |
void |
removeAll()
Remove all task objects from the task list and stops the task thread. |
void |
removeMember(java.lang.Object member)
Removes the Taskable object from the collection. |
void |
resume()
Resumes the execution of the task thread. |
void |
run()
Calls task on each of the task object in the internal task list. |
void |
setPriority(int newPriority)
Sets the priority of the thread. |
void |
setSleepTime(int newTime)
The sleepTime for the thread. |
int |
size()
Return the number of task current objects. |
void |
start()
This will create a thread and start it running, calling task on each of the items you have added to the TaskThread object. |
void |
stop()
This will destroy the thread and end the periodic calling of task objects. |
void |
suspend()
Suspends the execution of the task thread. |
java.lang.String |
toString()
String representation of the class. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public TaskThread(java.lang.String tName)
tName
- the name of the threadpublic TaskThread(java.lang.String tName, int sleepTime)
sleepTime
- sets the sleep time that will be used when the thread startsMethod Detail |
public static final void killAllThreads()
public int getSleepTime()
public void setSleepTime(int newTime)
public boolean addMember(java.lang.Object member)
addMember
in interface Collection
t
- a taskable client that wants to be called periodicallypublic boolean isAppropriate(java.lang.Object object)
isAppropriate
in interface Collection
public java.util.Enumeration members()
members
in interface Collection
public void addAndStart(Taskable t)
t
- the Taskable object to add to the collection.public void removeMember(java.lang.Object member)
removeMember
in interface Collection
t
- a task client that wants to be called periodicallypublic void removeAll()
public int size()
size
in interface Collection
public boolean hasMember(java.lang.Object object)
hasMember
in interface Collection
object
- the object to test if a memberpublic boolean isEmpty()
isEmpty
in interface Collection
public void start()
public void stop()
public void suspend()
public void resume()
public boolean isAlive()
public int getPriority()
public void setPriority(int newPriority)
newPriority
- the new priority of the thread or any consequent threads created.public void run()
run
in interface java.lang.Runnable
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |