Files
Hui-s-notebook/线程池.md
2023-09-10 10:50:53 +08:00

64 lines
936 B
Markdown

主要用于管理线程组及其运行状态
组成
- 线程池管理器
- 工作线程
- 任务接口
- 任务队列
ThreadPoolExecution
|序号|参数|说明|
|--|--|--|
|1|corePoolSize|核心线程|
|2|maxiumPoolSize|最大线程|
|3|keepAliveTime|空闲线程存活时间|
|4|unit|存活时间单位|
|5|workQueue|任务队列|
|6|threadFactory|线程工厂|
|7|handler|多余线程处理策略|
线程池拒绝策略
- AbortPolicy
- CallerRunsPolicy
- DiscardOldestPolicy
- DiscardPolicy
常用线程池
- newCachedThreadPool
- newFixedThreadPool
- newScheduledThreadPool
- newSingleThreadPool
- newWorkStealingPool
线程的生命周期
- New
- Runnable
- Running
- Blocked
- Dead
线程的基本方法
- wait
- sleep
- yield
- interrupt
- join
- notify
- setDaemon
sleep 和 wait 方法区别
start 方法和 run 方法区别
终止线程
- 正常运行结束
- 使用退出标志
- 使用 interrupt
- 使用stop