当前位置:网站首页>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!
边栏推荐
- AntDB数据库亮相24届高速展,助力智慧高速创新应用
- 三种方案解决:npm WARN config global --global, --local are deprecated. Use --location=global instead.
- tooltip control
- WinRAR | 将多个安装程序生成一个安装程序
- 食品安全 | 新鲜食品vs速食食品,哪一种是你的菜?
- SQL function TO_DATE (2)
- B011 - 基于51的多功能指纹智能锁
- Topology Parts Disassembly 3D Visualization Solution
- 解决MySQL插入不了中文数据问题
- 【全民编程】《软件编程-讲课视频》【零基础入门到实战应用】
猜你喜欢
随机推荐
Golang协程调度器scheduler怎么使用
Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021:解读
B005 - STC8 based single chip microcomputer intelligent street light control system
opencv基本的图像处理
Stop using MySQL online DDL
MySQL 45 讲 | 09 普通索引和唯一索引,应该怎么选择?
【Translation】OpenMetrics cultivated by CNCF becomes an incubation project
Leetcode75. Color Classification
QPalette palette, frame color fill
How to solve the dynamic binding of el-form-item prop attribute does not take effect
B011 - 基于51的多功能指纹智能锁
Review实战经典:2 种封装风格,你偏爱哪种?
Topology零部件拆解3D可视化解决方案
B002 - 基于嵌入式的老人定位追踪监测仪
如何让固定点的监控设备在EasyCVR平台GIS电子地图上显示地理位置?
塔防海岸线用户协议
Leetcode72. 编辑距离
opencv实时人脸检测
Prometheus的Recording rules实践
C language theory--a solid foundation for the written test and interview









