Class ThreadExecutorBuilder

java.lang.Object
org.miaixz.bus.core.lang.thread.ThreadExecutorBuilder

public class ThreadExecutorBuilder extends Object
类比 Executors
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Executor
    corePoolSize==0 maximumPoolSize==Integer.MAX_VALUE 队列:SynchronousQueue 创建一个线程池:当池中的线程都处于忙碌状态时,会立即新建一个线程来处理新来的任务 这种池将会在执行许多耗时短的异步任务的时候提高程序的性能 60秒钟内没有使用的线程将会被中止,并且从线程池中移除,因此几乎不必担心耗费资源
    static Executor
    newFixedFastThread(int corePoolSize, String prefix)
    创建一个线程数固定(corePoolSize==maximumPoolSize)的线程池 核心线程会一直存在,不被回收 如果一个核心线程由于异常跪了,会新创建一个线程 无界队列LinkedBlockingQueue
    static Executor
    newLimitedFastThread(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, String prefix, RejectedExecutionHandler handler)
    用给定的初始参数创建一个新的Executor

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ThreadExecutorBuilder

      public ThreadExecutorBuilder()
  • Method Details

    • newFixedFastThread

      public static Executor newFixedFastThread(int corePoolSize, String prefix)
      创建一个线程数固定(corePoolSize==maximumPoolSize)的线程池 核心线程会一直存在,不被回收 如果一个核心线程由于异常跪了,会新创建一个线程 无界队列LinkedBlockingQueue
      Parameters:
      corePoolSize - 要保留在池中的线程数,即使它们是空闲的
      prefix - 线程名前缀
    • newCachedFastThread

      public static Executor newCachedFastThread(String prefix)
      corePoolSize==0 maximumPoolSize==Integer.MAX_VALUE 队列:SynchronousQueue 创建一个线程池:当池中的线程都处于忙碌状态时,会立即新建一个线程来处理新来的任务 这种池将会在执行许多耗时短的异步任务的时候提高程序的性能 60秒钟内没有使用的线程将会被中止,并且从线程池中移除,因此几乎不必担心耗费资源
      Parameters:
      prefix - 线程名前缀
    • newLimitedFastThread

      public static Executor newLimitedFastThread(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, String prefix, RejectedExecutionHandler handler)
      用给定的初始参数创建一个新的Executor
      Parameters:
      corePoolSize - 要保留在池中的线程数,即使它们是空闲的
      maximumPoolSize - 池中允许的最大线程数
      keepAliveTime - 当线程数大于核心时,这是多余空闲线程在终止前等待新任务的最大时间。
      unit - keepAliveTime参数的时间单位
      workQueue - 任务执行之前用于保存任务的队列。此队列将仅保存由execute方法提交的可运行任务。
      prefix - 线程名前缀
      handler - 由于达到线程边界和队列容量而阻塞执行时使用的处理程序
      Returns:
      Executor