Package org.apache.hadoop.hbase.util
Class Threads
java.lang.Object
org.apache.hadoop.hbase.util.Threads
Thread Utility
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final org.slf4j.Logger
static final Thread.UncaughtExceptionHandler
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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.static boolean
Checks whether any non-daemon thread is running.static String
static void
printThreadInfo
(PrintStream stream, String title) Print all of the thread's information and stack traces.static <T extends Thread>
TUtility method that sets name, daemon status and starts passed thread.static <T extends Thread>
TsetDaemonThreadRunning
(T t, String name) Utility method that sets name, daemon status and starts passed thread.static <T extends Thread>
TsetDaemonThreadRunning
(T t, String name, Thread.UncaughtExceptionHandler handler) Utility method that sets name, daemon status and starts passed thread.static void
Sets an UncaughtExceptionHandler for the thread which logs the Exception stack if the thread dies.static void
Shutdown passed thread using isAlive and join.static void
Shutdown passed thread using isAlive and join.static void
sleep
(long millis) If interrupted, just prints out the interrupt on STDOUT, resets interrupt and returnsstatic void
sleepWithoutInterrupt
(long msToWait) Sleeps for the given amount of time even if interrupted.static void
Waits on the passed thread to die dumping a threaddump every minute while its up.
-
Field Details
-
LOG
-
LOGGING_EXCEPTION_HANDLER
-
-
Constructor Details
-
Threads
public Threads()
-
-
Method Details
-
setDaemonThreadRunning
Utility method that sets name, daemon status and starts passed thread.- Parameters:
t
- thread to run- Returns:
- Returns the passed Thread
t
.
-
setDaemonThreadRunning
Utility method that sets name, daemon status and starts passed thread.- Parameters:
t
- thread to frobname
- 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 frobname
- new namehandler
- A handler to set on the thread. Pass null if want to use default handler.- Returns:
- Returns the passed Thread
t
.
-
shutdown
Shutdown passed thread using isAlive and join.- Parameters:
t
- Thread to shutdown
-
shutdown
Shutdown passed thread using isAlive and join.- Parameters:
joinwait
- Pass 0 if we're to wait forever.t
- Thread to shutdown
-
threadDumpingIsAlive
Waits on the passed thread to die dumping a threaddump every minute while its up.- Throws:
InterruptedException
-
sleep
If interrupted, just prints out the interrupt on STDOUT, resets interrupt and returns- Parameters:
millis
- How long to sleep for in milliseconds.
-
sleepWithoutInterrupt
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 pooltimeout
- the maximum time to waitunit
- the time unit of the timeout argumentthreadFactory
- 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
Print all of the thread's information and stack traces. Wrapper around Hadoop's method.- Parameters:
stream
- the stream totitle
- a string title for the stack trace
-
isNonDaemonThreadRunning
Checks whether any non-daemon thread is running.- Returns:
- true if there are non daemon threads running, otherwise false
-
printStackTrace
-