org.ourgrid.test.threadServices
Class ThreadLists

java.lang.Object
  extended by org.ourgrid.test.threadServices.ThreadLists
Direct Known Subclasses:
ExtendedThreadLists

public class ThreadLists
extends java.lang.Object

This class handles the list of running and waiting threads of an application. It is used by the RunningThreadsMonitor aspect but is very general. The wait functionalities are suggested for service threads.


Constructor Summary
ThreadLists()
          Default constructor.
 
Method Summary
 void addWaiting(java.lang.Object o)
          Adds the current thread on the list of threads waiting for a certain object.
 void includeInRunningThreads(java.lang.Thread t)
          Include in running threads a given thread.
 void includeInStartedThreads(java.lang.Thread t)
          Include in running threads a given thread.
 boolean isThreadRunning(java.lang.Thread t)
          Verifies if a given thread is running (it has started its run method and has not leaved it.
 boolean isThreadStarted(java.lang.Thread t)
          Verifies if a given thread is started, but not running yet
 boolean isThreadWaiting(java.lang.Thread t)
          Verifies if a given thread is waiting
 void notifyAllWaitingThreads(java.lang.Object o)
          Notifies all theads waiting for an object o
 void notifyOneWaitingThread(java.lang.Object o)
          Notifies a thread that is waiting for an object o
 void println(java.lang.String str)
          General method that prints the string parameter on the standard output.
 void printRunningThreads()
          Prints the running threads.
 void printStartedThreads()
          Prints the started threads.
 void printWaitingThreads()
          Prints the waiting threads.
protected  void removeFromWaitingThreads(java.lang.Thread t)
          Removes a certain thread from the list of waiting threads.
 void removeRunnableThread()
          Removes a runnable thread from the list.
 void waitUntilAllThreadsDie()
          Waits until all running threads die.
 void waitUntilThreadHasFinished(java.lang.Thread t)
          Puts the current thread to wait until a certain Thread t leaves the run method.
 void waitUntilThreadHasStartedRunning(java.lang.Thread t)
          Waits until a given thread enters the run state.
 void waitUntilThreadIsWaiting(java.lang.Thread t)
          Waits until a given thread is waiting.
 void waitUntilWorkIsDoneNotifying()
          This method puts the current running thread to wait until all application running threads are waiting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadLists

public ThreadLists()
Default constructor.

Method Detail

waitUntilAllThreadsDie

public void waitUntilAllThreadsDie()
Waits until all running threads die. This method deserves more tests.


waitUntilWorkIsDoneNotifying

public void waitUntilWorkIsDoneNotifying()
This method puts the current running thread to wait until all application running threads are waiting.


waitUntilThreadHasFinished

public void waitUntilThreadHasFinished(java.lang.Thread t)
Puts the current thread to wait until a certain Thread t leaves the run method.

Parameters:
t - The thread we must wait until it stops running.

waitUntilThreadHasStartedRunning

public void waitUntilThreadHasStartedRunning(java.lang.Thread t)
Waits until a given thread enters the run state. Attention: Use this method when you know it will not leave the running state until you call it. It is more usefull in service threads. Due to the aspects, before any line of the run method, a thread will be included in the runningThreads. Use this method combined with waitUntilThreadIsWaiting when you have service threads.

Parameters:
t - The thread you want to wait for.

waitUntilThreadIsWaiting

public void waitUntilThreadIsWaiting(java.lang.Thread t)
Waits until a given thread is waiting.

Parameters:
t - The thread you want to wait for.

isThreadRunning

public boolean isThreadRunning(java.lang.Thread t)
Verifies if a given thread is running (it has started its run method and has not leaved it. Notice that it may also be waiting).

Parameters:
t - The wanted thread
Returns:
true if t is running.

isThreadStarted

public boolean isThreadStarted(java.lang.Thread t)
Verifies if a given thread is started, but not running yet

Parameters:
t - The wanted thread
Returns:
true if t is started, but not running yet.

isThreadWaiting

public boolean isThreadWaiting(java.lang.Thread t)
Verifies if a given thread is waiting

Parameters:
t - The wanted thread
Returns:
true if t is waiting.

includeInRunningThreads

public void includeInRunningThreads(java.lang.Thread t)
Include in running threads a given thread.

Parameters:
t - The thread to be included.

includeInStartedThreads

public void includeInStartedThreads(java.lang.Thread t)
Include in running threads a given thread.

Parameters:
t - The thread to be included.

removeFromWaitingThreads

protected void removeFromWaitingThreads(java.lang.Thread t)
Removes a certain thread from the list of waiting threads.

Parameters:
t - The thread to be removed.

addWaiting

public void addWaiting(java.lang.Object o)
Adds the current thread on the list of threads waiting for a certain object.

Parameters:
o - The waited object.

notifyAllWaitingThreads

public void notifyAllWaitingThreads(java.lang.Object o)
Notifies all theads waiting for an object o

Parameters:
o - The object where a notifyAll was called.

notifyOneWaitingThread

public void notifyOneWaitingThread(java.lang.Object o)
Notifies a thread that is waiting for an object o

Parameters:
o - The object where a notify was called.

printWaitingThreads

public void printWaitingThreads()
Prints the waiting threads.


printStartedThreads

public void printStartedThreads()
Prints the started threads.


printRunningThreads

public void printRunningThreads()
Prints the running threads.


removeRunnableThread

public void removeRunnableThread()
Removes a runnable thread from the list.


println

public void println(java.lang.String str)
General method that prints the string parameter on the standard output.

Parameters:
str - String to be printed.