当前位置:网站首页>ApplicationReadyEvent的使用
ApplicationReadyEvent的使用
2022-04-23 07:04:00 【一如年少丶】
前言
对于ApplicationReadyEvent,官网的解释是:事件尽可能晚发布,以指示应用程序已准备好为请求提供服务。该事件的来源是SpringApplication本身,但要注意修改其内部状态,因为届时所有初始化步骤都将完成。顾名思义就是SpringApplication准备就绪之后的事件,我们可以把一些有可能出现类未初始化异常的操作放在这里面执行
使用
@Component
public class BackendReadyEventListener implements ApplicationListener<ApplicationReadyEvent> {
private static final Logger LOGGER = LoggerFactory.getLogger(BackendReadyEventListener.class);
@Value("${thread.pool.coreSize:5}")
private int corePoolSize;
@Value("${thread.pool.maxSize:50}")
private int maxPoolSize;
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
//配置文件数据库缓存初始化
ConfigHelper configHelper = SpringContextUtils.getBean(ConfigHelper.class);
configHelper.initDatabaseCache();
//初始化线程池
new PoolExecutor(corePoolSize, maxPoolSize, new ThreadPoolExecutor.AbortPolicy());
}
}
比如,我在上述代码里面执行了配置文件数据库缓存初始化和初始化线程池等操作
版权声明
本文为[一如年少丶]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Yanzudada/article/details/124284538
边栏推荐
猜你喜欢

社区团购小程序源码+界面diy+附近团长+供应商+拼团+菜谱+秒杀+预售+配送+直播

Concours de compétences en informatique en nuage - - première partie de l'environnement cloud privé openstack

巨头押注的全屋智能,正在驱动海信、华为、小米们「自我革命」

Why are there 1px problems? How?

简述存储器的分级策略

LeetCode简单题之统计字符串中的元音子字符串

一款拥有漂亮外表的Typecho简洁主题_Scarfskin 源码下载

【Appium】测试时遇到手机内嵌H5页面的切换问题

LeetCode中等题之旋转函数

AAAI 2022 recruit speakers!!
随机推荐
岛屿的个数
[Effective Go 中文翻译]函数篇
PHP generates short links: convert numbers to letters and letters to numbers
[appium] encountered the problem of switching the H5 page embedded in the mobile phone during the test
LeetCode简单题之三除数
Construction of middleman environment mitmproxy
有意思的js 代码
LeetCoed18. Sum of four numbers
Brief description of CPU
将实例化对象的方法 给新的对象用
Codeforces Round #784 (Div. 4)
Go语学习笔记 - Slice、Map | 从零开始Go语言
Briefly describe the hierarchical strategy of memory
雲計算技能大賽 -- openstack私有雲環境 第一部分
1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
LeetCode15. Sum of three
Alibaba sentinel learning QA
Ignis公链的NFT生态发展:Unicorn.art的捐赠开发之路
AAAI 2022 recruit speakers!!
三星,再次“西征”