企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
``` java.util.concurrent.ThreadPoolExecutor 有4个构造方法,选取最多参数的那个来讲解 ``` **构造方法:** ``` public ThreadPoolExecutor( int corePoolSize, //核心线程池大小 int maximumPoolSize, //最大线程池大小 long keepAliveTime, //线程最大空闲时间 TimeUnit unit, //时间单位 BlockingQueue<Runnable> workQueue, //线程等等队列 ThreadFactory threadFactory, //线程创建工厂 RejectedExecutionHandler handler //拒绝策略 ) ``` **预定义线程池:** ``` ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(1); ExecutorService newCachedThreadPool = Executors.newCachedThreadPool(); ExecutorService newSingleThreadExecutor = Executors.newSingleThreadExecutor(); ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1); ```