@Async 異步背景
新增的數(shù)據(jù)需要分發(fā)給下游業(yè)務(wù)系統(tǒng),由于下游業(yè)務(wù)系統(tǒng)狀態(tài)未知,所以需要異步發(fā)送數(shù)據(jù)給下游業(yè)務(wù)系統(tǒng)。
系統(tǒng)生效按鈕--->controller新增-->異步調(diào)用servcie--->數(shù)據(jù)集成
在springboot框架中實(shí)現(xiàn)步驟
首先在啟動(dòng)類上加上@EnableAsync注解開啟項(xiàng)目的異步調(diào)用功能,其次需異步調(diào)用的方法上加上注解 @Async 即可實(shí)現(xiàn)方法的異步調(diào)用,再次在contorller使用的異步方法添加@Lazy
第一步:在啟動(dòng)類上加上 @EnableAsync 注解
?第二步添加現(xiàn)場池
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@Configuration
public class TaskExecutorBean {
public TaskExecutor getTaskExecutor() {
return new ThreadPoolTaskExecutor();
}
}
第三步:servcie方法添加異步注解@Async?
?第四步使用:在contorller中使用異步方法
文章來源:http://www.zghlxwxcb.cn/news/detail-596107.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-596107.html
到了這里,關(guān)于springboot @Async 異步調(diào)用接口處理數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!