All Packages Class Hierarchy This Package Previous Next Index
Class quicktime.app.time.TaskThread
java.lang.Object
|
+----quicktime.app.time.TaskThread
- public class TaskThread
- extends Object
- implements Runnable, Collection
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.
-
TaskThread(String)
- Creates a TaskThread object.
-
TaskThread(String, int)
- Creates a TaskThread object.
-
addAndStart(Taskable)
- This method will add a taskable client to the list.
-
addMember(Object)
- This method will add a taskable client to the list.
-
finalize()
-
-
getPriority()
- Returns the current priority of the task thread.
-
getSleepTime()
- The time that the thread will sleep.
-
hasMember(Object)
- Return true if the Taskable object is currently a member of the task list.
-
isAlive()
- Returns the alive state of the thread.
-
isAppropriate(Object)
- Returns true if the object is an instance of the Taskable interface.
-
isEmpty()
- Returns true if there are no Taskable objects in the collection
-
killAllThreads()
-
-
members()
- Returns an Enumeration for the current Taskable members of the collection.
-
removeAll()
- Remove all task objects from the task list and stops the task thread.
-
removeMember(Object)
- Removes the Taskable object from the collection.
-
resume()
- Resumes the execution of the task thread.
-
run()
- Calls task on each of the task object in the internal task list.
-
setPriority(int)
- Sets the priority of the thread.
-
setSleepTime(int)
- The sleepTime for the thread.
-
size()
- Return the number of task current objects.
-
start()
- This will create a thread and start it running, calling task on each of the items
you have added to the TaskThread object.
-
stop()
- This will destroy the thread and end the periodic calling of task objects.
-
suspend()
- Suspends the execution of the task thread.
-
toString()
- String representation of the class.
TaskThread
public TaskThread(String tName)
- Creates a TaskThread object. When the object's start method is called
the supplied name will be the name of the thread that is created by
the task thread object. The default sleep time for a TaskThread's thread
is 10msecs.
- Parameters:
- tName - the name of the thread
TaskThread
public TaskThread(String tName,
int sleepTime)
- Creates a TaskThread object. When the object's start method is called
the supplied name will be the name of the thread that is created by
the task thread object.
- Parameters:
- sleepTime - sets the sleep time that will be used when the thread starts
killAllThreads
public static final void killAllThreads()
getSleepTime
public int getSleepTime()
- The time that the thread will sleep.
setSleepTime
public void setSleepTime(int newTime)
- The sleepTime for the thread. If the sleepTime is set to zero, the thread will only
yield (but not sleep), otherwise it sleeps for the given time.
addMember
public boolean addMember(Object member)
- This method will add a taskable client to the list. It will not alter the state of the thread.
- Parameters:
- t - a taskable client that wants to be called periodically
isAppropriate
public boolean isAppropriate(Object object)
- Returns true if the object is an instance of the Taskable interface.
- Returns:
- a boolean
members
public Enumeration members()
- Returns an Enumeration for the current Taskable members of the collection.
- Returns:
- an Enumeration
addAndStart
public void addAndStart(Taskable t)
- This method will add a taskable client to the list.
If the thread was stopped (because there were no objects to task) this will start the thread up.
- Parameters:
- t - the Taskable object to add to the collection.
removeMember
public void removeMember(Object member)
- Removes the Taskable object from the collection. If this would leave
the collection empty then the internal thread is stopped.
- Parameters:
- t - a task client that wants to be called periodically
removeAll
public void removeAll()
- Remove all task objects from the task list and stops the task thread.
size
public int size()
- Return the number of task current objects.
- Returns:
- an int
hasMember
public boolean hasMember(Object object)
- Return true if the Taskable object is currently a member of the task list.
- Parameters:
- object - the object to test if a member
- Returns:
- true if the object is a member
isEmpty
public boolean isEmpty()
- Returns true if there are no Taskable objects in the collection
- Returns:
- a boolean
start
public 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. If a thread is already active this call has no effect
stop
public void stop()
- This will destroy the thread and end the periodic calling of task objects.
You can restart this object later by calling start.
The priority and sleepTime will be persistent across
start and stop calls, as will the task objects themselves.
suspend
public void suspend()
- Suspends the execution of the task thread.
resume
public void resume()
- Resumes the execution of the task thread.
isAlive
public boolean isAlive()
- Returns the alive state of the thread.
getPriority
public int getPriority()
- Returns the current priority of the task thread.
- Returns:
- the task thread priority or PRIORITY_NOT_SET if the TaskThread object has
not had a priority explicitly set.
setPriority
public void setPriority(int newPriority)
- Sets the priority of the thread.
- Parameters:
- newPriority - the new priority of the thread or any consequent threads created.
run
public void run()
- Calls task on each of the task object in the internal task list. If an object's
task call fails it is removed from the collection.
finalize
protected void finalize() throws Throwable
- Overrides:
- finalize in class Object
toString
public String toString()
- String representation of the class.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index