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);
    }
}
相关推荐
uzong3 小时前
Mermaid: AI 时代画图的魔法工具
后端·架构
q***69774 小时前
Spring Boot与MyBatis
spring boot·后端·mybatis
IUGEI5 小时前
synchronized的工作机制是怎样的?深入解析synchronized底层原理
java·开发语言·后端·c#
间彧5 小时前
GraalVM Native Image:跨平台能力与编译模式深度解析
后端
间彧5 小时前
GraalVM Native Image 与传统 JVM 内存管理:云原生时代的技术选型指南
后端
r***12385 小时前
SpringBoot最佳实践之 - 使用AOP记录操作日志
java·spring boot·后端
b***74886 小时前
前端GraphQL案例
前端·后端·graphql
LSL666_6 小时前
SpringBoot自动配置类
java·spring boot·后端·自动配置类
q***78376 小时前
Spring Boot 3.X:Unable to connect to Redis错误记录
spring boot·redis·后端
t***26597 小时前
SpringBoot + vue 管理系统
vue.js·spring boot·后端