当前位置:网站首页>The life cycle and scope
The life cycle and scope
2022-08-01 18:20:00 【Cool Xiaoya】
Article table of contents
Lifecycle and scope
Lifetime, and scope are critical, because incorrect usage can lead to very serious concurrency problems!
SqlSessionFactoryBuilder:
- Once the SqlSessionFactory is created, it is no longer needed
- Local variables
SqlSessionFactory:
- Can be imagined as: data connection pool
- Once created, the SqlSessionFactory should exist for the duration of the application's runtime,there is no reason to drop it or recreate another instance.
- So the best scope for SqlSessionFactory is application scope.
- The easiest way is to use Singleton mode or static mode.
SqlSession:
- A request to connect to the connection pool!
- Instances of SqlSession are not thread-safe and therefore cannot be shared, so their optimal scope is request or method scope.
- You need to close it after use, otherwise resources will be occupied!
边栏推荐
- 【Day_09 0427】 另类加法
- AIOps智能运维的领跑者擎创科技正式入驻InfoQ 写作社区!
- 突破性能天花板!亚信数据库支撑 10 多亿用户,峰值每秒百万交易
- The elder brother of the goldfish RHCA memoirs: CL210 experiment management it network - chapter
- Three solutions: npm WARN config global --global, --local are deprecated. Use --location=global instead.
- Leetcode73. 矩阵置零
- golang json 返回空值
- 生命周期和作用域
- How many steps does it take to convert an ENS domain name into music?
- typora操作手册
猜你喜欢
How opencv implements image skew correction
食品安全 | 新鲜食品vs速食食品,哪一种是你的菜?
B001 - Intelligent ecological fish tank based on STM32
QLineEdit学习与使用
Leetcode71. Simplified Paths
无需破解,官网安装Visual Studio 2013社区版
【Day_10 0428】井字棋
ExcelPatternTool: Excel表格-数据库互导工具
【Day_09 0427】走方格的方案数
一加OnePlus 10RT出现在Geekbench上 产品发布似乎也已临近
随机推荐
LeetCode 0152. 乘积最大子数组:dp + 原地滚动
MySQL 45 讲 | 09 普通索引和唯一索引,应该怎么选择?
打开微信客服
EpiSci | Deep Reinforcement Learning for SoCs: Myth and Reality
Live chat system technology (8) : vivo live IM message module architecture practice in the system
MySQL关系型数据库事务的ACID特性与实现方法
国标GB28181协议EasyGBS平台兼容老版本收流端口的功能实现
消息模板占位符的使用
Go GORM transaction instance analysis
Map传值
AntDB database appeared in the 24th high-speed exhibition, helping smart high-speed innovative applications
Go iota关键字与枚举类型实现原理是什么
EpiSci|片上系统的深度强化学习:神话与现实
Topology零部件拆解3D可视化解决方案
Industry Salon Phase II丨How to enable chemical companies to reduce costs and increase efficiency through supply chain digital business collaboration?
QT_QThread thread
LeetCode 0151.颠倒字符串中的单词
一加OnePlus 10RT出现在Geekbench上 产品发布似乎也已临近
2022年 PHP面试问题记录
将ENS域名转化为音乐需要几步?