类 ThreadUtils
- java.lang.Object
-
- network.nerve.core.thread.ThreadUtils
-
public class ThreadUtils extends Object
- 作者:
- tag
-
-
构造器概要
构造器 构造器 说明 ThreadUtils()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static <V> Future<V>asynExecuteCallable(Callable<V> callable)通过线程池执行任务static voidasynExecuteRunnable(Runnable runnable)通过线程池执行任务static voidcreateAndRunThread(String threadName, Runnable runnable)创建一个守望线程并执行static voidcreateAndRunThread(String threadName, Runnable runnable, boolean deamon)static ScheduledThreadPoolExecutorcreateScheduledThreadPool(int threadCount, NulsThreadFactory factory)创建一个ScheduledThreadPoolExecutor(定时执行的线程池)static ScheduledThreadPoolExecutorcreateScheduledThreadPool(NulsThreadFactory factory)创建一个核心线程数为1的ScheduledThreadPoolExecutor(定时执行的线程池)static ThreadPoolExecutorcreateThreadPool(int threadCount, int queueSize, NulsThreadFactory factory)创建线程池static List<Thread>getPoolThread(String poolName)获取指定线程工厂名称创建的线程static ThreadgetThread(String threadName)根据线程名称获取对应的线程static List<Thread>getThreadList()获取线程池中所有的线程static voidputThread(String poolName, String threadName, Thread newThread)想线程缓存中添加一个线程static voidstopAllThread()停止当前正在执行的所有线程static voidstopThread(String threadName)停止指定名称的线程
-
-
-
方法详细资料
-
putThread
public static final void putThread(String poolName, String threadName, Thread newThread)
想线程缓存中添加一个线程- 参数:
poolName- 线程工厂名称threadName- 线程名称newThread- 线程
-
createThreadPool
public static final ThreadPoolExecutor createThreadPool(int threadCount, int queueSize, NulsThreadFactory factory)
创建线程池- 参数:
threadCount- 线程池的核心线程数queueSize- 线程池所使用的缓冲队列长度factory- 线程池创建线程使用的工厂- 返回:
- ThreadPoolExecutor 线程池对象
-
createScheduledThreadPool
public static final ScheduledThreadPoolExecutor createScheduledThreadPool(int threadCount, NulsThreadFactory factory)
创建一个ScheduledThreadPoolExecutor(定时执行的线程池)- 参数:
threadCount- 线程池的核心线程数factory- 线程池创建线程使用的工厂- 返回:
- ScheduledThreadPoolExecutor 线程池对象
-
createScheduledThreadPool
public static final ScheduledThreadPoolExecutor createScheduledThreadPool(NulsThreadFactory factory)
创建一个核心线程数为1的ScheduledThreadPoolExecutor(定时执行的线程池)- 参数:
factory- 线程池创建线程使用的工厂- 返回:
- ScheduledThreadPoolExecutor 线程池对象
-
asynExecuteCallable
public static final <V> Future<V> asynExecuteCallable(Callable<V> callable)
通过线程池执行任务- 类型参数:
V-- 参数:
callable-- 返回:
-
asynExecuteRunnable
public static final void asynExecuteRunnable(Runnable runnable)
通过线程池执行任务- 参数:
runnable- Runnable
-
createAndRunThread
public static final void createAndRunThread(String threadName, Runnable runnable)
创建一个守望线程并执行- 参数:
threadName- 线程名称runnable- Runnable
-
createAndRunThread
public static final void createAndRunThread(String threadName, Runnable runnable, boolean deamon)
-
getThread
public static Thread getThread(String threadName)
根据线程名称获取对应的线程- 参数:
threadName- 线程名称- 返回:
- Thread
-
getPoolThread
public static List<Thread> getPoolThread(String poolName)
获取指定线程工厂名称创建的线程- 参数:
poolName- 线程工厂名称- 返回:
- List
-
stopAllThread
public static void stopAllThread()
停止当前正在执行的所有线程
-
stopThread
public static void stopThread(String threadName)
停止指定名称的线程- 参数:
threadName- 线程名称
-
-