当前位置:网站首页>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
边栏推荐
- 几种智能机器人室内定位方法对比
- C 输出一种二维数组,特点如下。
- [programming practice / embedded competition] learning record of embedded competition (I): establishment of TCP server and web interface
- 数据库之MySQL——基本常用查询命令
- LeetCode中等题之旋转函数
- Flatten arrays
- 干货!以点为形:可微分的泊松求解器
- 渗透测试面试合集---HVV---
- NIH降血脂指南《your guide to lowering your Cholesterol with TLC》笔记(持续更新中)
- 在MATLAB中快速画圆(给出圆心坐标和半径就能直接画的那种)
猜你喜欢
在线YAML转XML工具
Why are there 1px problems? How?
Samsung, March to the west again
Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
数据库之MySQL——基础篇
Discussion on ES6 tail tune optimization
搜一下导航完整程序源码
BUUCTF [极客大挑战 2019]EasySQL1
青苹果影视系统源码 影视聚合 影视导航 影视点播网站源码
[programming practice / embedded competition] learning record of embedded competition (I): establishment of TCP server and web interface
随机推荐
RAID0和RAID5的创建和模拟RAID5工作原理
剑指offer day24 数学(中等)
Go语学习笔记 - Slice、Map | 从零开始Go语言
一篇文章看懂变量提升(hoisting)
Cloud computing skills competition -- the first part of openstack private cloud environment
浅谈ES6尾调优化
AAAI 2022招募讲者啦!!
LeetCode15. 三数之和
js将树形结构数据转为一维数组数据
PHP generates short links: convert numbers to letters and letters to numbers
Talking about distributed storage from ES, mongodb, redis and rocketmq
Usage of databinding
Hierarchical output binary tree
在线YAML转XML工具
php高精度计算
Intranet penetration series: icmptunnel of Intranet tunnel (Master James Barlow's)
青苹果影视系统源码 影视聚合 影视导航 影视点播网站源码
Hump naming object
NLLLoss+log_SoftMax=CE_Loss
[appium] encountered the problem of switching the H5 page embedded in the mobile phone during the test