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);
    }
}
相关推荐
是真的小外套6 小时前
第十五章:XXE漏洞攻防与其他漏洞全解析
后端·计算机网络·php
ybwycx8 小时前
SpringBoot下获取resources目录下文件的常用方法
java·spring boot·后端
小陈工8 小时前
Python Web开发入门(十一):RESTful API设计原则与最佳实践——让你的API既优雅又好用
开发语言·前端·人工智能·后端·python·安全·restful
小阳哥AI工具8 小时前
Seedance 2.0使用真人参考图生成视频的方法
后端
IeE1QQ3GT9 小时前
使用ASP.NET Abstractions增强ASP.NET应用程序的可测试性
后端·asp.net
Full Stack Developme9 小时前
SpringBoot多线程池配置
spring boot·后端·firefox
sxhcwgcy11 小时前
SpringBoot 使用 spring.profiles.active 来区分不同环境配置
spring boot·后端·spring
稻草猫.13 小时前
Spring事务操作全解析
java·数据库·后端·spring
希望永不加班13 小时前
SpringBoot 整合 MongoDB
java·spring boot·后端·mongodb·spring
Lzh编程小栈14 小时前
数据结构与算法之队列深度解析:循环队列+C 语言硬核实现 + 面试考点全梳理
c语言·开发语言·汇编·数据结构·后端·算法·面试