当前位置:网站首页>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!
边栏推荐
猜你喜欢

QT_QThread线程

在Map传值与对象传值中模糊查询

How to solve the dynamic binding of el-form-item prop attribute does not take effect

XAML WPF项目groupBox控件

【Day_09 0427】走方格的方案数

OpenCV安装、QT、VS配置项目设置

C language theory--a solid foundation for the written test and interview

暑假第二周总结博客

亚马逊云科技Build On2022技能提升计划第二季——揭秘出海爆款新物种背后的黑科技

打开微信客服
随机推荐
QT_QThread线程
Prometheus的Recording rules实践
Detailed explanation of DBPack SQL Tracing function and data encryption function
How to use the Golang coroutine scheduler scheduler
Topology零部件拆解3D可视化解决方案
typora操作手册
QPalette palette, frame color fill
【LeetCode】Day109-最长回文串
粒子滤波 particle filter —从贝叶斯滤波到粒子滤波——Part-I(贝叶斯滤波)
el-form-item prop属性动态绑定不生效如何解决
【Day_11 0506】求最大连续bit数
QT_Event class
LeetCode 0151.颠倒字符串中的单词
MySQL Lock wait timeout exceeded; try restarting transaction 锁等待
B005 - STC8 based single chip microcomputer intelligent street light control system
WinRAR | Generate multiple installers into one installer
QPalette调色板、框架色彩填充
7月30号|来一场手把手助您打造智能视觉新爆款的技术动手实验
Leetcode74. 搜索二维矩阵
How to solve the dynamic binding of el-form-item prop attribute does not take effect