public class ThreadPoolUtil extends Object
| Constructor and Description |
|---|
ThreadPoolUtil() |
| Modifier and Type | Method and Description |
|---|---|
static ThreadFactory |
buildThreadFactory(String threadNamePrefix)
创建ThreadFactory,使得创建的线程有自己的名字而不是默认的"pool-x-thread-y"
使用了Guava的工具类
|
static ThreadFactory |
buildThreadFactory(String threadNamePrefix,
boolean daemon)
可设定是否daemon, daemon线程在主线程已执行完毕时, 不会阻塞应用不退出, 而非daemon线程则会阻塞.
|
static boolean |
gracefulShutdown(ExecutorService threadPool,
int shutdownTimeoutMills)
按照ExecutorService JavaDoc示例代码编写的Graceful Shutdown方法.
|
static boolean |
gracefulShutdown(ExecutorService threadPool,
int shutdownTimeout,
TimeUnit timeUnit) |
static Runnable |
safeRunnable(Runnable runnable)
防止用户没有捕捉异常导致中断了线程池中的线程, 使得SchedulerService无法继续执行.
|
public static boolean gracefulShutdown(ExecutorService threadPool, int shutdownTimeoutMills)
MoreExecutors.shutdownAndAwaitTermination(ExecutorService, long, TimeUnit)public static boolean gracefulShutdown(ExecutorService threadPool, int shutdownTimeout, TimeUnit timeUnit)
gracefulShutdownpublic static ThreadFactory buildThreadFactory(String threadNamePrefix)
ThreadFactoryBuilder.build()public static ThreadFactory buildThreadFactory(String threadNamePrefix, boolean daemon)
buildThreadFactoryCopyright © 2018. All rights reserved.