我想着重强调的就是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
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。