类 ThreadUtils


  • public class ThreadUtils
    extends Object
    作者:
    tag
    • 构造器详细资料

      • ThreadUtils

        public ThreadUtils()
    • 方法详细资料

      • 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)
      • getThreadList

        public static final List<Thread> getThreadList()
        获取线程池中所有的线程
        返回:
        List
      • 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 - 线程名称