public class Threads extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Threads.WrapExceptionRunnable
保证不会有Exception抛出到线程池的Runnable,防止用户没有捕捉异常导致中断了线程池中的线程。
|
| Constructor and Description |
|---|
Threads() |
| Modifier and Type | Method and Description |
|---|---|
static ThreadFactory |
buildJobFactory(String nameFormat)
创建ThreadFactory,使得创建的线程有自己的名字而不是默认的"pool-x-thread-y",
在用threaddump查看线程时特别有用。 格式如"mythread-%d",使用了Guava的工具类
|
static void |
gracefulShutdown(ExecutorService pool,
int shutdownTimeout,
int shutdownNowTimeout,
TimeUnit timeUnit)
按照ExecutorService JavaDoc示例代码编写的Graceful Shutdown方法.
|
static void |
normalShutdown(ExecutorService pool,
int timeout,
TimeUnit timeUnit)
直接调用shutdownNow的方法, 有timeout控制.取消在workQueue中Pending的任务,并中断所有阻塞函数.
|
static void |
sleep(long durationMillis)
sleep等待, 单位为毫秒.
|
static void |
sleep(long duration,
TimeUnit unit)
sleep等待.
|
public static void sleep(long durationMillis)
public static void sleep(long duration,
TimeUnit unit)
public static ThreadFactory buildJobFactory(String nameFormat)
public static void gracefulShutdown(ExecutorService pool, int shutdownTimeout, int shutdownNowTimeout, TimeUnit timeUnit)
public static void normalShutdown(ExecutorService pool, int timeout, TimeUnit timeUnit)
Copyright © 2020. All rights reserved.