当前位置:网站首页>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!
边栏推荐
- C#/VB.NET:从 PDF 文档中提取所有表格
- 【无标题】setInterval和setTimeout详解
- 【Translation】OpenMetrics cultivated by CNCF becomes an incubation project
- Break the performance ceiling!AsiaInfo database supports more than 1 billion users, with a peak of one million transactions per second
- opencv syntax Mat type summary
- ExcelPatternTool: Excel表格-数据库互导工具
- 暑假第二周总结博客
- odoo 编码规范(编程规范、编码指南)
- 【Day_08 0426】求最小公倍数
- XML配置
猜你喜欢

【Day_11 0506】 最近公共祖先

C语言理论--笔试面试基础稳固

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

云原生全景图详解

【Day_09 0427】走方格的方案数

QPalette palette, frame color fill

C#/VB.NET: extracted from the PDF document all form

JVM运行时数据区与JMM内存模型是什么

Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021:解读

【Day_09 0427】 另类加法
随机推荐
粒子滤波 particle filter —从贝叶斯滤波到粒子滤波——Part-I(贝叶斯滤波)
消息模板占位符的使用
Summer vacation second week wrap-up blog
What is the implementation principle of Go iota keyword and enumeration type
钳形万用表使用方法,如何测量电压、电流、电阻?
WinRAR | Generate multiple installers into one installer
SQL函数 TO_DATE(二)
SQL function TO_DATE (1)
阿里云的域名和ip绑定
QLineEdit learning and use
QT_QThread thread
OpenCV installation, QT, VS configuration project settings
Tower Defense Shoreline User Agreement
AntDB数据库亮相24届高速展,助力智慧高速创新应用
中信证券是国内十大券商吗?怎么开户安全?
LeetCode 0152. 乘积最大子数组:dp + 原地滚动
暑假第二周总结博客
ACID Characteristics and Implementation Methods of MySQL Relational Database Transactions
【Day_09 0427】 另类加法
深入浅出Flask PIN