@InterfaceAudience.Private public class Threads extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected static Log |
LOG |
static java.lang.Thread.UncaughtExceptionHandler |
LOGGING_EXCEPTION_HANDLER |
| Constructor and Description |
|---|
Threads() |
| Modifier and Type | Method and Description |
|---|---|
static java.util.concurrent.ThreadPoolExecutor |
getBoundedCachedThreadPool(int maxCachedThread,
long timeout,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.ThreadFactory threadFactory)
Create a new CachedThreadPool with a bounded number as the maximum
thread size in the pool.
|
static java.util.concurrent.ThreadFactory |
getNamedThreadFactory(java.lang.String prefix)
Returns a
ThreadFactory that names each created thread uniquely,
with a common prefix. |
static java.util.concurrent.ThreadFactory |
newDaemonThreadFactory(java.lang.String prefix)
Same as {#newDaemonThreadFactory(String, UncaughtExceptionHandler)},
without setting the exception handler.
|
static java.util.concurrent.ThreadFactory |
newDaemonThreadFactory(java.lang.String prefix,
java.lang.Thread.UncaughtExceptionHandler handler)
Get a named
ThreadFactory that just builds daemon threads. |
static void |
printThreadInfo(java.io.PrintStream stream,
java.lang.String title)
Print all of the thread's information and stack traces.
|
static java.lang.Thread |
setDaemonThreadRunning(java.lang.Thread t)
Utility method that sets name, daemon status and starts passed thread.
|
static java.lang.Thread |
setDaemonThreadRunning(java.lang.Thread t,
java.lang.String name)
Utility method that sets name, daemon status and starts passed thread.
|
static java.lang.Thread |
setDaemonThreadRunning(java.lang.Thread t,
java.lang.String name,
java.lang.Thread.UncaughtExceptionHandler handler)
Utility method that sets name, daemon status and starts passed thread.
|
static void |
setLoggingUncaughtExceptionHandler(java.lang.Thread t)
Sets an UncaughtExceptionHandler for the thread which logs the
Exception stack if the thread dies.
|
static void |
shutdown(java.lang.Thread t)
Shutdown passed thread using isAlive and join.
|
static void |
shutdown(java.lang.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(java.lang.Thread t) |
protected static final Log LOG
public static final java.lang.Thread.UncaughtExceptionHandler LOGGING_EXCEPTION_HANDLER
public static java.lang.Thread setDaemonThreadRunning(java.lang.Thread t)
t - thread to runt.public static java.lang.Thread setDaemonThreadRunning(java.lang.Thread t,
java.lang.String name)
t - thread to frobname - new namet.public static java.lang.Thread setDaemonThreadRunning(java.lang.Thread t,
java.lang.String name,
java.lang.Thread.UncaughtExceptionHandler handler)
t - thread to frobname - new namehandler - A handler to set on the thread. Pass null if want to
use default handler.t.public static void shutdown(java.lang.Thread t)
t - Thread to shutdownpublic static void shutdown(java.lang.Thread t,
long joinwait)
joinwait - Pass 0 if we're to wait forever.t - Thread to shutdownpublic static void threadDumpingIsAlive(java.lang.Thread t)
throws java.lang.InterruptedException
t - Waits on the passed thread to die dumping a threaddump every
minute while its up.java.lang.InterruptedExceptionpublic static void sleep(long millis)
millis - How long to sleep for in milliseconds.public static void sleepWithoutInterrupt(long msToWait)
msToWait - the amount of time to sleep in millisecondspublic static java.util.concurrent.ThreadPoolExecutor getBoundedCachedThreadPool(int maxCachedThread,
long timeout,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.ThreadFactory threadFactory)
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 threadspublic static java.util.concurrent.ThreadFactory getNamedThreadFactory(java.lang.String prefix)
ThreadFactory that names each created thread uniquely,
with a common prefix.prefix - The prefix of every created Thread's nameThreadFactory that names threadspublic static java.util.concurrent.ThreadFactory newDaemonThreadFactory(java.lang.String prefix)
public static java.util.concurrent.ThreadFactory newDaemonThreadFactory(java.lang.String prefix,
java.lang.Thread.UncaughtExceptionHandler handler)
ThreadFactory that just builds daemon threads.prefix - name prefix for all threads created from the factoryhandler - unhandles exception handler to set for all threadspublic static void setLoggingUncaughtExceptionHandler(java.lang.Thread t)
public static void printThreadInfo(java.io.PrintStream stream,
java.lang.String title)
stream - the stream totitle - a string title for the stack trace