org.cdlib.xtf.util
Class ThreadWatcher

Object
  extended by ThreadWatcher

public class ThreadWatcher
extends Object

Keeps an eye on threads, and logs those that appear to be "runaways".


Nested Class Summary
private static class ThreadWatcher.Entry
          Keeps track of one thread we're watching.
 
Field Summary
private static HashMap beingWatched
           
private static Thread watcherThread
           
 
Constructor Summary
ThreadWatcher()
           
 
Method Summary
static void beginWatch(String descrip, long normalTime, long killTime)
          Notifies the watcher that the current thread is about to begin an operation that might turn into a runaway.
static void endWatch()
          Notifies the watcher that the current thread has completed the operation begun after beginWatch(String,long,long).
static int nRunaways()
          Counts the number of runaway threads at the moment.
static boolean shouldDie(Thread thread)
          Tells whether the specified thread has exceeded its kill limit and should kill itself off.
private static void watch()
          This is the worker function that runs in a separate thread and keeps an eye out for runaways.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

beingWatched

private static HashMap beingWatched

watcherThread

private static Thread watcherThread
Constructor Detail

ThreadWatcher

public ThreadWatcher()
Method Detail

beginWatch

public static void beginWatch(String descrip,
                              long normalTime,
                              long killTime)
Notifies the watcher that the current thread is about to begin an operation that might turn into a runaway. If it does, the specified description will be used in log messages. The thread should call endWatch() when it completes the operation.

Parameters:
descrip - Description of the operation being started, used for log messages.
normalTime - Max number of milliseconds the operation is expected to take, after which warnings will be printed about the thread being "runaway."
killTime - Number of milliseconds after which the thread should be killed (by setting a flag that hopefully it will check.)

endWatch

public static void endWatch()
Notifies the watcher that the current thread has completed the operation begun after beginWatch(String,long,long).


nRunaways

public static int nRunaways()
Counts the number of runaway threads at the moment.


shouldDie

public static boolean shouldDie(Thread thread)
Tells whether the specified thread has exceeded its kill limit and should kill itself off.


watch

private static void watch()
This is the worker function that runs in a separate thread and keeps an eye out for runaways.