Class Threads

java.lang.Object
org.apache.hadoop.hbase.util.Threads

@Private public class Threads extends Object
Thread Utility
  • Field Details

  • Constructor Details

  • Method Details

    • setDaemonThreadRunning

      public static <T extends Thread> T setDaemonThreadRunning(T t)
      Utility method that sets name, daemon status and starts passed thread.
      Parameters:
      t - thread to run
      Returns:
      Returns the passed Thread t.
    • setDaemonThreadRunning

      public static <T extends Thread> T setDaemonThreadRunning(T t, String name)
      Utility method that sets name, daemon status and starts passed thread.
      Parameters:
      t - thread to frob
      name - new name
      Returns:
      Returns the passed Thread t.
    • setDaemonThreadRunning

      public static <T extends Thread> T setDaemonThreadRunning(T t, String name, Thread.UncaughtExceptionHandler handler)
      Utility method that sets name, daemon status and starts passed thread.
      Parameters:
      t - thread to frob
      name - new name
      handler - A handler to set on the thread. Pass null if want to use default handler.
      Returns:
      Returns the passed Thread t.
    • shutdown

      public static void shutdown(Thread t)
      Shutdown passed thread using isAlive and join.
      Parameters:
      t - Thread to shutdown
    • shutdown

      public static void shutdown(Thread t, long joinwait)
      Shutdown passed thread using isAlive and join.
      Parameters:
      joinwait - Pass 0 if we're to wait forever.
      t - Thread to shutdown
    • threadDumpingIsAlive

      public static void threadDumpingIsAlive(Thread t) throws InterruptedException
      Waits on the passed thread to die dumping a threaddump every minute while its up.
      Throws:
      InterruptedException
    • sleep

      public static void sleep(long millis)
      If interrupted, just prints out the interrupt on STDOUT, resets interrupt and returns
      Parameters:
      millis - How long to sleep for in milliseconds.
    • sleepWithoutInterrupt

      public static void sleepWithoutInterrupt(long msToWait)
      Sleeps for the given amount of time even if interrupted. Preserves the interrupt status.
      Parameters:
      msToWait - the amount of time to sleep in milliseconds
    • getBoundedCachedThreadPool

      public static ThreadPoolExecutor getBoundedCachedThreadPool(int maxCachedThread, long timeout, TimeUnit unit, ThreadFactory threadFactory)
      Create a new CachedThreadPool with a bounded number as the maximum thread size in the pool.
      Parameters:
      maxCachedThread - the maximum thread could be created in the pool
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      threadFactory - the factory to use when creating new threads
      Returns:
      threadPoolExecutor the cachedThreadPool with a bounded number as the maximum thread size in the pool.
    • setLoggingUncaughtExceptionHandler

      Sets an UncaughtExceptionHandler for the thread which logs the Exception stack if the thread dies.
    • printThreadInfo

      public static void printThreadInfo(PrintStream stream, String title)
      Print all of the thread's information and stack traces. Wrapper around Hadoop's method.
      Parameters:
      stream - the stream to
      title - a string title for the stack trace
    • isNonDaemonThreadRunning

      public static boolean isNonDaemonThreadRunning()
      Checks whether any non-daemon thread is running.
      Returns:
      true if there are non daemon threads running, otherwise false
    • printStackTrace

      public static String printStackTrace(Thread t)