开发者社区> 问答> 正文

Spring 中有哪些和ThreadPoolExecutor 类似的工具?

Spring 中有哪些和ThreadPoolExecutor 类似的工具?

展开
收起
Medusa 2021-10-19 19:16:38 441 0
1 条回答
写回答
取消 提交回答
  • 配图5.png

    我想着重强调的就是SimpleAsyncTaskExecutor,Spring 中使用的@Async 注解,底层就是基于SimpleAsyncTaskExecutor 去执行任务,只不过它不是线程池,而是每次都新开一个线程。 另外想要强调的是Executor 接口。Java 初学者容易想当然的以为Executor 结尾的类就是一个线程池。我们可以在JDK 的execute 方法上看到这个注释:

    /**
    * Executes the given command at some time in the future. The command
    * may execute in a new thread, in a pooled thread, or in the calling
    * thread, at the discretion of the {@code Executor} implementation.
    */
    
    

    所以,它的职责并不是提供一个线程池的接口,而是提供一个“将来执行命令”的接口。真正能代表线程池意义的,是ThreadPoolExecutor 类,而不是Executor 接口。

    资料来源:《Java开发者面试百宝书》,链接:https://developer.aliyun.com/topic/download?id=7899

    2021-10-20 12:10:25
    赞同 1 展开评论 打赏
来源圈子
更多
收录在圈子:
阿里云开发者社区官方技术圈,用户产品功能发布、用户反馈收集等。
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载