Package alluxio.util
Class ThreadUtils
- java.lang.Object
-
- alluxio.util.ThreadUtils
-
public final class ThreadUtils extends java.lang.Object
Utility method for working with threads.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
formatStackTrace(java.lang.Thread thread)
static java.lang.String
formatStackTrace(java.lang.Throwable t)
Return formatted stacktrace of Throwable instance.static java.lang.String
getCurrentThreadIdentifier()
static java.lang.String
getThreadIdentifier(java.lang.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, java.lang.String title, long minInterval)
Log the current thread stacks at INFO level.static void
printThreadInfo(java.io.PrintStream stream, java.lang.String title)
Prints the information and stack traces of all threads.static void
shutdownAndAwaitTermination(java.util.concurrent.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.
-
-
-
Method Detail
-
formatStackTrace
public static java.lang.String formatStackTrace(java.lang.Thread thread)
- Parameters:
thread
- a thread- Returns:
- a human-readable representation of the thread's stack trace
-
formatStackTrace
public static java.lang.String formatStackTrace(java.lang.Throwable t)
Return formatted stacktrace of Throwable instance.- Parameters:
t
- - a Throwable instance- Returns:
- a human-readable representation of the Throwable's stack trace
-
logAllThreads
public static void logAllThreads()
Logs a stack trace for all threads currently running in the JVM, similar to jstack.
-
shutdownAndAwaitTermination
public static void shutdownAndAwaitTermination(java.util.concurrent.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.- Parameters:
pool
- the executor service to shutdowntimeoutMs
- how long to wait for the service to shut down
-
getCurrentThreadIdentifier
public static java.lang.String getCurrentThreadIdentifier()
- Returns:
- a string representation of the current thread
-
getThreadIdentifier
public static java.lang.String getThreadIdentifier(java.lang.Thread thread)
- Parameters:
thread
- the thread- Returns:
- a string representation of the given thread
-
printThreadInfo
public static void printThreadInfo(java.io.PrintStream stream, java.lang.String title)
Prints the information and stack traces of all threads. In order not to pause the JVM when there are tons of threads, thread stacks are printed one by one. So the thread stacks are not guaranteed to be based on one consistent snapshot.- Parameters:
stream
- the stream totitle
- a string title for the stack trace
-
logThreadInfo
public static void logThreadInfo(org.slf4j.Logger log, java.lang.String title, long minInterval)
Log the current thread stacks at INFO level.- Parameters:
log
- the logger that logs the stack tracetitle
- a descriptive title for the call stacksminInterval
- the minimum time from the last, unit is second
-
-