public final class ThreadTools
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
destroyThreadGroup(java.lang.ThreadGroup group,
long joinTimeout,
java.util.logging.Logger logger,
java.util.logging.Level logLevel)
Destroys the designated thread group if desired (
joinTimeout >= 0). |
static void |
dumpAllThreads(java.io.PrintStream out)
Dumps stack traces of all current threads to
out. |
static java.lang.String |
getCurrentStackTraces(java.lang.ThreadGroup group,
java.util.logging.Logger logger)
Gets the stack traces of all the threads in the designated thread group as
string formatted like the usual string representation of a stacktrace.
|
static java.lang.Thread[] |
getThreads(java.lang.ThreadGroup group,
java.util.logging.Logger logger)
Gets all threads of the designated thread group.
|
public static java.lang.Thread[] getThreads(java.lang.ThreadGroup group,
java.util.logging.Logger logger)
group - The thread group of which to recursively retrieve the threads.logger - The logger in which to log the log messages.public static void dumpAllThreads(java.io.PrintStream out)
out.out - Target to print the stack dumps to.public static java.lang.String getCurrentStackTraces(java.lang.ThreadGroup group,
java.util.logging.Logger logger)
group - The thread group of which to retrieve the stack traces of all
threads.logger - The logger in which to log the log messages.public static boolean destroyThreadGroup(java.lang.ThreadGroup group,
long joinTimeout,
java.util.logging.Logger logger,
java.util.logging.Level logLevel)
joinTimeout >= 0). First all active threads are interrupted.
Then their termination is awaited with the designated timeout. Threads
still running after that will be stopped . Their
termination will be awaited again. If all threads terminated in time, the
designated thread group will be destroyed. joinTimeout < 0, the thread group will only be destroyed if
all its threads have terminated. Otherwise the thread group will not be
destroyed and the threads will keep on running.group - The thread group to be destroyed. If this is null
, the method call will be ignored.joinTimeout - The time in milliseconds to wait for each thread after
interrupting and again after stopping it (if required). If this
value is negative, the group will only be destroyed if all threads
have terminated. Otherwise they will keep on running.logger - The logger in which to log the log messages.logLevel - The log level which to use for logging running threads. If
their termination is forced, this is always Level.SEVERE.