当前位置:网站首页>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语言学习记录——삼십팔 字符串函数使用和剖析(2)
- RAID0和RAID5的创建和模拟RAID5工作原理
- 一款拥有漂亮外表的Typecho简洁主题_Scarfskin 源码下载
- mysql查询字符串类型的字段使用数字类型查询时问题
- How does feign integrate hystrix
- Find the largest of 3 strings (no more than 20 characters per string).
- Compiler des questions de principe - avec des réponses
- LeetCode15. 三数之和
- Thinkphp6 + JWT realizes login verification
- LeetCode简单题之统计字符串中的元音子字符串
猜你喜欢
随机推荐
Go语学习笔记 - 结构体 | 从零开始Go语言
Brief description of CPU
Flutter之Provider共享数据的两种方式
一款拥有漂亮外表的Typecho简洁主题_Scarfskin 源码下载
访问数据库的时候出现错误 Operation not allowed for a result set of type ResultSet.TYPE_FORWARD_ONLY.详解
利用sqlmap注入获取网址管理员账号密码
DataBinding的使用五
js将树形结构数据转为一维数组数据
C语言学习记录——삼십팔 字符串函数使用和剖析(2)
多目视觉SLAM
Planification du mouvement du manipulateur dans l'assemblage 3c
Mobile web (Font Icon, plane conversion, color gradient)
Summary of facial classics
Convert object to URL
PHP generates short links: convert numbers to letters and letters to numbers
Move layout (Flex layout, viewport label)
Feign source code analysis
谈谈那些基础但不简单的股票数据
LeetCode 1611. 使整数变为 0 的最少操作次数
扎心了!一女子发朋友圈羡慕别人按时发工资被开除,连点赞的同事也一同被开除了...