public final class ThreadUtils extends Object
Modifier and Type | Method and Description |
---|---|
static String |
formatStackTrace(Thread thread) |
static String |
getCurrentThreadIdentifier() |
static String |
getThreadIdentifier(Thread thread) |
static void |
logAllThreads()
Logs a stack trace for all threads currently running in the JVM, similar to jstack.
|
static void |
logThreadInfo(org.slf4j.Logger log,
String title,
long minInterval)
Log the current thread stacks at INFO level.
|
static void |
printThreadInfo(PrintStream stream,
String title)
Prints the information and stack traces of all threads.
|
static void |
shutdownAndAwaitTermination(ExecutorService pool,
long timeoutMs)
From https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html
The following method shuts down an ExecutorService in two phases, first by calling shutdown to
reject incoming tasks, and then calling shutdownNow, if necessary, to cancel any lingering
tasks.
|
public static String formatStackTrace(Thread thread)
thread
- a threadpublic static void logAllThreads()
public static void shutdownAndAwaitTermination(ExecutorService pool, long timeoutMs)
pool
- the executor service to shutdowntimeoutMs
- how long to wait for the service to shut downpublic static String getCurrentThreadIdentifier()
public static String getThreadIdentifier(Thread thread)
thread
- the threadpublic static void printThreadInfo(PrintStream stream, String title)
stream
- the stream totitle
- a string title for the stack tracepublic static void logThreadInfo(org.slf4j.Logger log, String title, long minInterval)
log
- the logger that logs the stack tracetitle
- a descriptive title for the call stacksminInterval
- the minimum time from the last, unit is secondCopyright © 2023. All Rights Reserved.