org.apache.hadoop.hbase.util
Class Threads

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

@InterfaceAudience.Private
public class Threads
extends Object

Thread Utility


Field Summary
protected static org.apache.commons.logging.Log LOG
           
 
Constructor Summary
Threads()
           
 
Method Summary
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.
static ThreadFactory getNamedThreadFactory(String prefix)
          Returns a ThreadFactory that names each created thread uniquely, with a common prefix.
static ThreadFactory newDaemonThreadFactory(String prefix)
          Same as {#newDaemonThreadFactory(String, UncaughtExceptionHandler)}, without setting the exception handler.
static ThreadFactory newDaemonThreadFactory(String prefix, Thread.UncaughtExceptionHandler handler)
          Get a named ThreadFactory that just builds daemon threads.
static void printThreadInfo(PrintStream stream, String title)
          Print all of the thread's information and stack traces.
static Thread setDaemonThreadRunning(Thread t)
          Utility method that sets name, daemon status and starts passed thread.
static Thread setDaemonThreadRunning(Thread t, String name)
          Utility method that sets name, daemon status and starts passed thread.
static Thread setDaemonThreadRunning(Thread t, String name, Thread.UncaughtExceptionHandler handler)
          Utility method that sets name, daemon status and starts passed thread.
static void shutdown(Thread t)
          Shutdown passed thread using isAlive and join.
static void shutdown(Thread t, long joinwait)
          Shutdown passed thread using isAlive and join.
static void sleep(long millis)
          If interrupted, just prints out the interrupt on STDOUT, resets interrupt and returns
static void sleepWithoutInterrupt(long msToWait)
          Sleeps for the given amount of time even if interrupted.
static void threadDumpingIsAlive(Thread t)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG
Constructor Detail

Threads

public Threads()
Method Detail

setDaemonThreadRunning

public static Thread setDaemonThreadRunning(Thread 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 Thread setDaemonThreadRunning(Thread 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 Thread setDaemonThreadRunning(Thread 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
Parameters:
t - 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.

getNamedThreadFactory

public static ThreadFactory getNamedThreadFactory(String prefix)
Returns a ThreadFactory that names each created thread uniquely, with a common prefix.

Parameters:
prefix - The prefix of every created Thread's name
Returns:
a ThreadFactory that names threads

newDaemonThreadFactory

public static ThreadFactory newDaemonThreadFactory(String prefix)
Same as {#newDaemonThreadFactory(String, UncaughtExceptionHandler)}, without setting the exception handler.


newDaemonThreadFactory

public static ThreadFactory newDaemonThreadFactory(String prefix,
                                                   Thread.UncaughtExceptionHandler handler)
Get a named ThreadFactory that just builds daemon threads.

Parameters:
prefix - name prefix for all threads created from the factory
handler - unhandles exception handler to set for all threads
Returns:
a thread factory that creates named, daemon threads with the supplied exception handler and normal priority

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


Copyright © 2007-2015 The Apache Software Foundation. All Rights Reserved.