ThreadPoolExecutor参数说明
来源:互联网 发布:缅甸听音乐的软件 编辑:程序博客网 时间:2024/05/01 17:36
1、前言
目前很多框架都会需要有一个线程池,来维护所有的异步任务,管理的生命周期,也能够更方便的调用执行。所以ThreadPoolExecutor使用的时候,对其参数一定需要很清晰。所以自己去亲自动手,才是最放心的。
2、ThreadPoolExecutor构造方法源码
/** * Creates a new {@code ThreadPoolExecutor} with the given initial * parameters. * * @param corePoolSize the number of threads to keep in the pool, even * if they are idle, unless {@code allowCoreThreadTimeOut} is set * @param maximumPoolSize the maximum number of threads to allow in the * pool * @param keepAliveTime when the number of threads is greater than * the core, this is the maximum time that excess idle threads * will wait for new tasks before terminating. * @param unit the time unit for the {@code keepAliveTime} argument * @param workQueue the queue to use for holding tasks before they are * executed. This queue will hold only the {@code Runnable} * tasks submitted by the {@code execute} method. * @param threadFactory the factory to use when the executor * creates a new thread * @param handler the handler to use when execution is blocked * because the thread bounds and queue capacities are reached * @throws IllegalArgumentException if one of the following holds:<br> * {@code corePoolSize < 0}<br> * {@code keepAliveTime < 0}<br> * {@code maximumPoolSize <= 0}<br> * {@code maximumPoolSize < corePoolSize} * @throws NullPointerException if {@code workQueue} * or {@code threadFactory} or {@code handler} is null */ public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler) { if (corePoolSize < 0 || maximumPoolSize <= 0 || maximumPoolSize < corePoolSize || keepAliveTime < 0) throw new IllegalArgumentException(); if (workQueue == null || threadFactory == null || handler == null) throw new NullPointerException(); this.corePoolSize = corePoolSize; this.maximumPoolSize = maximumPoolSize; this.workQueue = workQueue; this.keepAliveTime = unit.toNanos(keepAliveTime); this.threadFactory = threadFactory; this.handler = handler; }
3、参数说明
corePoolSize
corePoolSize the number of threads to keep in the pool, even if they are idle, unless {@code allowCoreThreadTimeOut} is set
核心线程池的大小,表示线程池初始化的时候给核心存活的大小,就算没有任务需要执行,如果没有设置allowCoreThreadTimeOut的话,就会一直存活。
maximumPoolSize
maximumPoolSize the maximum number of threads to allow in the pool
线程池中最大可容纳的线程数,如果线程池中,提交的线程超过了corePoolSize,还可以继续提交,但是不能超过
keepAliveTime
keepAliveTime when the number of threads is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating.
当线程池中的线程数大于核心线程数量时,无用的线程等待任务执行的最大存活的时间。
TimeUnit
unit the time unit for the {@code keepAliveTime} argument
时间单位的枚举,标识keepAliveTime的时间单位
workQueue
workQueue the queue to use for holding tasks before they are executed. This queue will hold only the {@code Runnable} tasks submitted by the {@code execute} method.
管理通过execute方法提交的未执行的任务的队列
threadFactory
the factory to use when the executor creates a new thread
thread工厂类,用于executor产生新thread
handler
the handler to use when execution is blocked because the thread bounds and queue capacities are reached
当线程池达到最大值,且排队的队列满了的时候,就会拒绝新的任务加入时一个处理拒绝加入的回调。
0 0
- ThreadPoolExecutor参数说明
- ThreadPoolExecutor参数说明
- ThreadPoolExecutor参数说明
- ThreadPoolExecutor线程池参数说明
- ThreadPoolExecutor线程池参数说明
- 线程测试参数ThreadPoolExecutor()
- ThreadPoolExecutor构造参数介绍
- ThreadPoolExecutor 参数详解
- ThreadPoolExecutor的参数介绍
- 【并发编程】ThreadPoolExecutor参数详解
- Android ThreadPoolExecutor 的参数详解
- ThreadPoolExecutor方法参数的解释
- java 线程池ThreadPoolExecutor类参数测试
- Java中ThreadPoolExecutor的参数理解
- [JAVA学习笔记-65]ThreadPoolExecutor参数解析
- ThreadPoolExecutor机制及各参数讲…
- Android线程池ThreadPoolExecutor参数详解
- ThreadPoolExecutor机制及各参数讲解
- PE文件结构详解--基本概念
- 近百个免费API接口分享 调用完全不限次数
- class org.bouncycastle.asn1.ASN1Primitive overrides final method equals.(Ljava/lang/Object;)Z
- 分布式系统唯一ID生成方案汇总
- 《设计模式之禅》读书笔记
- ThreadPoolExecutor参数说明
- 判断网络状态工具类
- MongoDB connection timeout
- <戏说春秋> 第二关 纸上谈兵
- Git Gui for Windows的建库、克隆(clone)、上传(push)、下载(pull)、合并(转)
- TestView添加切割线,类似商品打折
- Dalvik Vm架构
- iOS 自定义对象数组排序 自定义对象某属性排序
- mybatis--No constructor found