live.threads
Class ActiveThreadsInfo

java.lang.Object
  extended bylive.threads.ActiveThreadsInfo

public class ActiveThreadsInfo
extends Object

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

inProgress

private LinkedList inProgress

recentlyComplete

private LinkedList recentlyComplete

completedJobs

private LinkedList completedJobs

timeThreshold

private int timeThreshold
The length of time a thread must be active for before it will be added to the recently complete list. This is so that every little query and whatnot will not show up in the header.

Constructor Detail

ActiveThreadsInfo

public ActiveThreadsInfo()
Method Detail

markInProgress

public void markInProgress(ThreadedUserAction t)
Marks the thread as currently running

Parameters:
t - The ThreadedUserActionthat is starting to run

markComplete

public void markComplete(ThreadedUserAction t)
Marks the thread as ending. In other words, it moves it from the list of in-progress threads to done threads. If the thread took longer than timeThreshold milliseconds to run, adds it to the recently complete list too.

Parameters:
t - The ThreadedUserActionthat is starting to run

getRecentlyComplete

public LinkedList getRecentlyComplete()
This function returns a list of threads that have ended (called markComplete) since the last time it was called. There is no synchronization issue outside of this function; calling code has free reign over the use of it, and the list and all the threads in it will be GC'd after it loses its reference to it. (Currently. Do not depend on this GCing occuring.)

Returns:
A list of ThreadedUserActions passed to markComplete(live.threads.ThreadedUserAction)since the last call

getCompletedJobs

public LinkedList getCompletedJobs()
This function returns a list of threads that have been completed sometime somewhat sort of recently. This is deliberately vague.

Returns:
A list of ThreadedUserActions that have been completed in the past

getInProgress

public LinkedList getInProgress()
This function returns a list of threads that are currently running (have not called markComplete). Here (as opposed to 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.

Returns:
A list of ThreadedUserActions passed to markInProgress(live.threads.ThreadedUserAction)but not markComplete(live.threads.ThreadedUserAction)

setTimeThreshold

public void setTimeThreshold(int newThreshold)
This sets timeThreshold.

Parameters:
newThreshold - The new threshold value


Copyright © 2005