Java 异步调用

概念

同步:就是在发出一个调用时,在没有得到结果之前,该调用就不返回(实时处理)

异步:调用在发出之后,这个调用就直接返回了,没有返回结果(分时处理)

代码

在执行异步的方法上添加@Async

less 复制代码
@Slf4j
@Transactional
@Service
public class ArticleFreemarkerServiceImpl implements ArticleFreemarkerService  {

    @Async
    @Override
    public void buildArticleToMinIO(ApArticle apArticle, String content) {
    
            xxxxxx     
            
            }
    }

引导类使用@EnableAsync开启异步调用

less 复制代码
@SpringBootApplication
@EnableAsync
public class ArticleApplication {

    public static void main(String[] args) {
        SpringApplication.run(ArticleApplication.class,args);
    }
}
相关推荐
csdn_aspnet2 分钟前
如何在 ASP.NET Core Identity 中实现用户身份验证
后端·asp.net·.net core·identity
康小庄3 分钟前
SpringBoot 拦截器 (Interceptor) 与切面 (AOP):示例、作用、及适用场景
java·数据库·spring boot·后端·mysql·spring·spring cloud
中科院提名者19 分钟前
如何配置go环境并用vscode运行
开发语言·后端·golang
huahailing102427 分钟前
Spring Boot 3.x + JDK17 参数校验全场景实战(含List列表_嵌套_分组)
spring boot·后端
毕设源码-朱学姐1 小时前
【开题答辩全过程】以 基于spring boot的摩托车合格证管理系统为例,包含答辩的问题和答案
java·spring boot·后端
毕设源码-赖学姐1 小时前
【开题答辩全过程】以 基于spring boot的国学诗词网站设计与实现--为例,包含答辩的问题和答案
java·spring boot·后端
千寻技术帮2 小时前
10410_基于Springboot的文化旅游宣传网站
spring boot·后端·vue·源码·旅游·安装·在线旅游
源码宝2 小时前
前后端分离架构:不良事件管理系统源码(Vue2+Element UI+Laravel 8)
后端·php·源码·二次开发·程序·不良事件上报·医院不良事件管理系统
Remember_9932 小时前
【LeetCode精选算法】位运算专题
java·开发语言·jvm·后端·算法·leetcode
源代码•宸2 小时前
Leetcode—102. 二叉树的层序遍历【中等】
经验分享·后端·算法·leetcode·职场和发展·golang·slice