public class ThreadUtils extends Object
| 构造器和说明 |
|---|
ThreadUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <V> Future<V> |
asynExecuteCallable(Callable<V> callable)
通过线程池执行任务
|
static void |
asynExecuteRunnable(Runnable runnable)
通过线程池执行任务
|
static void |
createAndRunThread(String threadName,
Runnable runnable)
创建一个守望线程并执行
|
static void |
createAndRunThread(String threadName,
Runnable runnable,
boolean deamon) |
static ScheduledThreadPoolExecutor |
createScheduledThreadPool(int threadCount,
NulsThreadFactory factory)
创建一个ScheduledThreadPoolExecutor(定时执行的线程池)
|
static ScheduledThreadPoolExecutor |
createScheduledThreadPool(NulsThreadFactory factory)
创建一个核心线程数为1的ScheduledThreadPoolExecutor(定时执行的线程池)
|
static ThreadPoolExecutor |
createThreadPool(int threadCount,
int queueSize,
NulsThreadFactory factory)
创建线程池
|
static List<Thread> |
getPoolThread(String poolName)
获取指定线程工厂名称创建的线程
|
static Thread |
getThread(String threadName)
根据线程名称获取对应的线程
|
static List<Thread> |
getThreadList()
获取线程池中所有的线程
|
static void |
putThread(String poolName,
String threadName,
Thread newThread)
想线程缓存中添加一个线程
|
static void |
stopAllThread()
停止当前正在执行的所有线程
|
static void |
stopThread(String threadName)
停止指定名称的线程
|
public static final void putThread(String poolName, String threadName, Thread newThread)
poolName - 线程工厂名称threadName - 线程名称newThread - 线程public static final ThreadPoolExecutor createThreadPool(int threadCount, int queueSize, NulsThreadFactory factory)
threadCount - 线程池的核心线程数queueSize - 线程池所使用的缓冲队列长度factory - 线程池创建线程使用的工厂public static final ScheduledThreadPoolExecutor createScheduledThreadPool(int threadCount, NulsThreadFactory factory)
threadCount - 线程池的核心线程数factory - 线程池创建线程使用的工厂public static final ScheduledThreadPoolExecutor createScheduledThreadPool(NulsThreadFactory factory)
factory - 线程池创建线程使用的工厂public static final <V> Future<V> asynExecuteCallable(Callable<V> callable)
V - callable - public static final void asynExecuteRunnable(Runnable runnable)
runnable - Runnablepublic static final void createAndRunThread(String threadName, Runnable runnable)
threadName - 线程名称runnable - Runnablepublic static final void createAndRunThread(String threadName, Runnable runnable, boolean deamon)
public static Thread getThread(String threadName)
threadName - 线程名称public static List<Thread> getPoolThread(String poolName)
poolName - 线程工厂名称public static void stopAllThread()
public static void stopThread(String threadName)
threadName - 线程名称Copyright © 2021. All rights reserved.