Class ThreadPool

java.lang.Object
cn.sinozg.applet.common.utils.ThreadPool

public class ThreadPool extends Object
线程池对象
  • Field Details

    • SHUT_TIME

      private static final int SHUT_TIME
      See Also:
    • log

      private static final org.slf4j.Logger log
    • TTL_SERVICE

      private static final ExecutorService TTL_SERVICE
      多线程下可以获取用户信息的 线程池
    • SINGLE_THREAD_POOL

      private static final ThreadPoolExecutor SINGLE_THREAD_POOL
      创建线程池 普通线程池
  • Constructor Details

    • ThreadPool

      private ThreadPool()
  • Method Details

    • submit

      public static void submit(Runnable runnable)
    • execute

      public static void execute(Runnable runnable)
    • ttlExecute

      public static void ttlExecute(Runnable r)
      可以在子线程里面获取到用户信息
      Parameters:
      r - 线程方法
    • shutdownAndAwaitTermination

      public static void shutdownAndAwaitTermination()
      停止线程池 先使用shutdown, 停止接收新任务并尝试完成所有已存在任务. 如果超时, 则调用shutdownNow, 取消在workQueue中Pending的任务,并中断所有阻塞函数. 如果仍人超時,則強制退出. 另对在shutdown时线程本身被调用中断做了处理.
    • shutdownAndAwaitTermination

      public static void shutdownAndAwaitTermination(ExecutorService pool)
      停止线程池 先使用shutdown, 停止接收新任务并尝试完成所有已存在任务. 如果超时, 则调用shutdownNow, 取消在workQueue中Pending的任务,并中断所有阻塞函数. 如果仍人超時,則強制退出. 另对在shutdown时线程本身被调用中断做了处理.
    • printException

      public static void printException(Runnable r, Throwable t)
      打印线程异常信息
    • scheduledThread

      public static ScheduledThreadPoolExecutor scheduledThread(String poolName)
      创建一个 延迟线程池
      Parameters:
      poolName - 名称
      Returns:
      延迟线程池
    • scheduleWithFixedDelay

      public static ScheduledFuture<?> scheduleWithFixedDelay(ScheduledThreadPoolExecutor executor, Runnable command, Duration initialDelay, Duration delay)
      执行延迟任务 下次任务开始时间以上次任务结束时间开始 加上延迟的间隔时间
      Parameters:
      executor - 线程池
      command - 任务
      initialDelay - 延迟时间 秒
      delay - 延迟间隔时间
      Returns:
      返回结果
    • scheduleAtFixedRate

      public static ScheduledFuture<?> scheduleAtFixedRate(ScheduledThreadPoolExecutor executor, Runnable command, Duration initialDelay, Duration period)
      执行延迟任务 任务执行时间超过间隔时间的 直接执行
      Parameters:
      executor - 线程池
      command - 任务
      initialDelay - 延迟时间
      period - 间隔时间
      Returns:
      返回结果