当前位置:网站首页>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!
边栏推荐
- ACID Characteristics and Implementation Methods of MySQL Relational Database Transactions
- Live chat system technology (8) : vivo live IM message module architecture practice in the system
- Topology零部件拆解3D可视化解决方案
- Leetcode72. 编辑距离
- XAML WPF item groupBox control
- CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) Solution
- Zabbix6.0 DingTalk robot alarm
- opencv语法Mat类型总结
- Go iota关键字与枚举类型实现原理是什么
- QLineEdit学习与使用
猜你喜欢
OnePlus 10RT appears on Geekbench, product launch also seems to be approaching
Stop using MySQL online DDL

QLineEdit学习与使用

MySQL 45 Talk | 09 How to choose common index and unique index?

【Day_09 0427】走方格的方案数

QT commonly used global macro definitions

深入浅出Flask PIN

QPalette调色板、框架色彩填充

explain 各字段介绍

B005 – 基于STC8的单片机智能路灯控制系统
随机推荐
MySQL数据库————流程控制
【Day_12 0507】二进制插入
How opencv implements image skew correction
【Day_12 0507】查找组成一个偶数最接近的两个素数
Leetcode74. 搜索二维矩阵
成都理工大学&电子科技大学|用于强化学习的域自适应状态表示对齐
【Day_11 0506】求最大连续bit数
opencv基本的图像处理
三维空间中点的插值
MySQL database - stored procedures and functions
8月微软技术课程,欢迎参与
QT基础功能,信号、槽
QT_QThread线程
OpenCV安装、QT、VS配置项目设置
关于单应性矩阵的若干思考
想随时、随地、随心使用数据库的朋友们,全体注意!
【Day_11 0506】 最近公共祖先
QLineEdit学习与使用
无需破解,官网安装Visual Studio 2013社区版
将ENS域名转化为音乐需要几步?