Java线程中的ThreadPoolExecutor
来源:互联网 发布:淘宝金丝绒太极服 编辑:程序博客网 时间:2024/06/06 07:29
Java线程中的ThreadPoolExecutor
Java线程中的ThreadPoolExecutor是ExecutorService接口的实现类,其通过线程池中的线程来执行提交的任务。
线程池主要用来解决两个问题:一是用来解决大量异步任务导致的性能问题,它降低了每个任务调用的系统开销,二是其提供了对线程资源的管理。ThreadPoolExecutor自身维护了其一些属性,比如已完成的任务数等。
JDK提供了一些简便配置thread pool的方法:
- Executors.newCachedThreadPool() (unbounded thread pool, with automatic thread reclamation)
- Executors.newFixedThreadPool(int) (fixed size thread pool)
- Executors.newSingleThreadExecutor() (single background thread)
如果我们要更加灵活地配置thread pool时,那么就要配置一下参数:
corePoolSize: 线程池维护线程的最少数量
maximumPoolSize:线程池维护线程的最大数量
keepAliveTime: 线程池维护线程所允许的空闲时间
unit: 线程池维护线程所允许的空闲时间的单位
workQueue: 线程池所使用的缓冲队列
handler: 线程池对拒绝任务的处理策略
0 0
- Java线程中的ThreadPoolExecutor
- JAVA中的线程池-ThreadPoolExecutor
- Java 线程池ThreadPoolExecutor
- Java 线程池ThreadPoolExecutor
- Java 线程池ThreadPoolExecutor
- JAVA线程池:ThreadPoolExecutor
- JAVA线程池ThreadPoolExecutor
- JAVA线程池ThreadPoolExecutor
- ThreadPoolExecutor java 线程池
- Java 线程池ThreadPoolExecutor
- java 线程池ThreadPoolExecutor
- JAVA线程池ThreadPoolExecutor
- java线程池:ThreadPoolExecutor
- Java线程池ThreadPoolExecutor
- Java 线程池 ThreadPoolExecutor
- java线程池ThreadPoolExecutor
- Java线程池ThreadPoolExecutor
- java 线程池ThreadPoolExecutor
- 在做自动化测试之前你需要知道的
- serialize a list of string and deserialize it
- leetcode #14 LongestCommenPrefix
- groovy 把json串转化成对象
- find maximized count of 0 on left and 1 on right in binary array
- Java线程中的ThreadPoolExecutor
- 利用jdk.tar.gz部署在CentOS/RedHat Enterprise Linux上
- Android屏幕关闭时开机CPU运行(以传感器为例)
- leetcode #1 TwoSum
- 冲动是魔鬼,冷静也是魔鬼(草稿)
- missing ranges of sorted integer array
- 谈谈exifread
- 远程访问hdfs
- c-free配置c++11