public class ThreadWatcher
extends Object
Modifier and Type | Class and Description |
---|---|
private static class |
ThreadWatcher.Entry
Keeps track of one thread we're watching.
|
Modifier and Type | Field and Description |
---|---|
private static HashMap |
beingWatched |
private static Thread |
watcherThread |
Constructor and Description |
---|
ThreadWatcher() |
Modifier and Type | Method and Description |
---|---|
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.
|
private static HashMap beingWatched
private static Thread watcherThread
public static void beginWatch(String descrip, long normalTime, long killTime)
endWatch()
when it completes the operation.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.)public static void endWatch()
beginWatch(String,long,long)
.public static int nRunaways()
public static boolean shouldDie(Thread thread)
private static void watch()