|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlive.threads.ActiveThreadsInfo
This class tracks what threads are currently active. When a thread begins
processing (begins its run), it should call
markInProgress(ThreadedUserAction)
. When a thread ends its
processing, it should call markComplete(ThreadedUserAction)
. Both
functions take one parameter, which is the thread that is starting or
finishing. (So essentially this
from whichever thread is
running.)
In addition, you can get a list of the threads that are currently running,
and a list of those that have been completed since the last call. TODO: A
longer list into the past
When synchronizing on multiple objects, it is imperative that one do it in
the order inProgress, then recentlyComplete, then completedJobs in order to
avoid deadlocks. If only synchronizing on two of the above, you still must do
it in the same order. Client code need not lock on recentlyComplete at
all, but if using both the inProgress or completeJobs objects synchronization
is a must (and in that order if using both).
Field Summary | |
private LinkedList |
completedJobs
|
private LinkedList |
inProgress
|
private LinkedList |
recentlyComplete
|
private int |
timeThreshold
The length of time a thread must be active for before it will be added to the recently complete list. |
Constructor Summary | |
ActiveThreadsInfo()
|
Method Summary | |
LinkedList |
getCompletedJobs()
This function returns a list of threads that have been completed sometime somewhat sort of recently. |
LinkedList |
getInProgress()
This function returns a list of threads that are currently running (have not called markComplete). |
LinkedList |
getRecentlyComplete()
This function returns a list of threads that have ended (called markComplete) since the last time it was called. |
void |
markComplete(ThreadedUserAction t)
Marks the thread as ending. |
void |
markInProgress(ThreadedUserAction t)
Marks the thread as currently running |
void |
setTimeThreshold(int newThreshold)
This sets timeThreshold . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private LinkedList inProgress
private LinkedList recentlyComplete
private LinkedList completedJobs
private int timeThreshold
Constructor Detail |
public ActiveThreadsInfo()
Method Detail |
public void markInProgress(ThreadedUserAction t)
t
- The ThreadedUserAction
that is starting to runpublic void markComplete(ThreadedUserAction t)
timeThreshold
milliseconds to run, adds it to the recently
complete list too.
t
- The ThreadedUserAction
that is starting to runpublic LinkedList getRecentlyComplete()
ThreadedUserAction
s passed to
markComplete(live.threads.ThreadedUserAction)
since the last callpublic LinkedList getCompletedJobs()
ThreadedUserAction
s that have been completed
in the pastpublic LinkedList getInProgress()
getRecentlyComplete()
there IS a
synchronization issue, and calling code must synchronize on it. This
function does not want to take the time to duplicate the list to return
while potentially blocking other threads from executing, but it needs
continued use of the list.
ThreadedUserAction
s passed to
markInProgress(live.threads.ThreadedUserAction)
but not markComplete(live.threads.ThreadedUserAction)
public void setTimeThreshold(int newThreshold)
timeThreshold
.
newThreshold
- The new threshold value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |