1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-06-16 18:10:13 +08:00

Merge pull request #1163 from vfmh/master

update java线程池学习总结.md
This commit is contained in:
Guide哥 2021-04-16 22:30:24 +08:00 committed by GitHub
commit 6de1055b4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -715,7 +715,7 @@ Wed Nov 13 13:40:43 CST 2019::pool-1-thread-5
#### 5.1.3 为什么不推荐使用`FixedThreadPool` #### 5.1.3 为什么不推荐使用`FixedThreadPool`
**`FixedThreadPool` 使用无界队列 `LinkedBlockingQueue`(队列的容量为 Intger.MAX_VALUE作为线程池的工作队列会对线程池带来如下影响 ** **`FixedThreadPool` 使用无界队列 `LinkedBlockingQueue`(队列的容量为 Integer.MAX_VALUE作为线程池的工作队列会对线程池带来如下影响 **
1. 当线程池中的线程数达到 `corePoolSize` 后,新任务将在无界队列中等待,因此线程池中的线程数不会超过 corePoolSize 1. 当线程池中的线程数达到 `corePoolSize` 后,新任务将在无界队列中等待,因此线程池中的线程数不会超过 corePoolSize
2. 由于使用无界队列时 `maximumPoolSize` 将是一个无效参数,因为不可能存在任务队列满的情况。所以,通过创建 `FixedThreadPool`的源码可以看出创建的 `FixedThreadPool``corePoolSize``maximumPoolSize` 被设置为同一个值。 2. 由于使用无界队列时 `maximumPoolSize` 将是一个无效参数,因为不可能存在任务队列满的情况。所以,通过创建 `FixedThreadPool`的源码可以看出创建的 `FixedThreadPool``corePoolSize``maximumPoolSize` 被设置为同一个值。