Package alluxio.util

Class 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 shutdown
        timeoutMs - 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.
        Parameters:
        stream - the stream to
        title - 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 trace
        title - a descriptive title for the call stacks
        minInterval - the minimum time from the last, unit is second