java - Spring Async 问题:仅使用 Autowired 实例创建的新线程,而不是创建的“新”线程
问题描述
尝试了异步演示项目:https ://github.com/huanzi-qch/springBoot/tree/master/springboot-async 。它对我来说很好。但事实证明,如果实例是由“new”关键字创建的,带有“Async”注解的方法将在同一个线程中执行!!这种不同行为的原因是什么?
@Autowired
private TestService testService;
...
System.out.println(Thread.currentThread().getName() + ":开始调用异步业务");
//无返回值
//TestService testService = new TestServiceImpl(); // If uncomment this line, no new thread created
testService.asyncTask();
解决方案
推荐阅读
- python - Gattlib 安装有 pip 问题
- php - 如何将sql查询转换为laravel查询
- mongodb - 如何使用 Zabbix 进行 MongoDB 监控
- sequelize.js - sequelize 在 v6.6.5 中没有设置标准主键“id”
- schema.org - 如何覆盖 schema.org 标记中数组中项目的@type?
- c++ - 写入映射结构区域失败
- javascript - 通过在同一键下连接值将数组转换为对象
- python-3.x - 一维相同时翻转维度
- javascript - 当服务器部署到heroku时,快速会话不是持久的
- nginx - 我需要哪些 DNS TXT 记录?