Java源码-ThreadPoolExecutor
1 Executors工具类创建ThreadPoolExecutor
SingleThreadExecutor | newFixedThreadPool | newCachedThreadPool | newScheduledThreadPool | newSingleThreadScheduledExecutor | |
---|---|---|---|---|---|
corePoolSize | 1 | n | 0 | n | 1 |
maximumPoolSize | 1 | n | Integer.MAX_VALUE | Integer.MAX_VALUE | Integer.MAX_VALUE |
keepAliveTime | 0 | 0 | SECONDS | 10 | 10 |
unit | MILLISECONDS | MILLISECONDS | SECONDS | MILLISECONDS | MILLISECONDS |
workQueue | LinkedBlockingQueue | LinkedBlockingQueue | SynchronousQueue | DelayedWorkQueue | DelayedWorkQueue |
threadFactory | DefaultThreadFactory | DefaultThreadFactory | DefaultThreadFactory | DefaultThreadFactory | DefaultThreadFactory |
handler | AbortPolicy | AbortPolicy | AbortPolicy | AbortPolicy | AbortPolicy |
2 类图
3 构造方法
java
1 |
|
4 提交任务到线程池
java
1 |
|
线程池状态
新任务 | 正在执行的任务 | 任务队列任务 | 调用terminated() | |
---|---|---|---|---|
RUNNING | ✔ | ✔ | ✔ | ✗ |
SHUTDOWN | ✗ | ✔ | ✔ | ✗ |
STOP | ✗ | ✗ | ✗ | ✗ |
TIDYING | ✗ | ✗ | ✗ | ✔ |
TERMINATED | ✗ | ✗ | ✗ | ✗ |
4.1 线程池接收任务
java
1 |
|
4.2 线程池创建线程
4.2.1 线程池中的线程对象
java
1 |
|
4.2.2 工作线程创建和启动
java
1 |
|
4.3 线程池线程模型
java
1 |
|
java
1 |
|
java
1 |
|
4.4 工作线程保活
java
1 |
|
Java源码-ThreadPoolExecutor
https://bannirui.github.io/2023/03/11/Java源码-ThreadPoolExecutor/