Java多线程系列(十七)五种线程池

本文详细介绍了Java中五种主要线程池的特性和使用场景:newCachedThreadPool允许线程无限创建;newFixedThreadPool维持固定数量的线程;newSingleThreadExecutor使用单一工作线程;newScheduledThreadPool支持定时和周期性任务调度;newWorkStealingPool采用Fork/Join框架实现任务窃取算法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.newCachedThreadPool   线程无限加

 Creates a thread pool that creates new threads as needed, but
     * will reuse previously constructed threads when they are
     * available.

2.newFixedThreadPool   线程固定

Creates a thread pool that reuses a fixed number of threads
     * operating off a shared unbounded queue.

3.newSingleThreadExecutor  单thread

Creates an Executor that uses a single worker thread operating
     * off an unbounded queue.

4.newScheduledThreadPool  支持定期及周期任务

 Creates a thread pool that can schedule commands to run after a
     * given delay, or to execute periodically.

5.newWorkStealingPool   forkjoin  分而治之

参考 https://www.jianshu.com/p/135c89001b61

参考 https://blog.youkuaiyun.com/cx105200/article/details/80220937#threadpoolexecutor

参考 https://www.jianshu.com/p/50fffbf21b39

使用:submit  execute

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值