当前位置:网站首页>生命周期和作用域
生命周期和作用域
2022-08-01 18:18:00 【酷小亚】
生命周期和作用域

生命周期,和作用域是至关重要的,因为错误的使用会导致非常严重的并发问题!
SqlSessionFactoryBuilder:
- 一旦创建了SqlSessionFactory,就不再需要它了
- 局部变量
SqlSessionFactory:
- 可以想象为:数据连接池
- SqlSessionFactory一旦被创建就应该在应用的运行期间一直存在,没有任何理由丢弃它或重新创建另一个实例。
- 因此SqlSessionFactory的最佳作用域是应用作用域。
- 最简单的就是使用单例模式或者静态模式。
SqlSession:
- 连接到连接池的一个请求!
- SqlSession的实例不是线程安全的,因此是不能被共享的,所以它的最佳的作用域是请求或方法作用域。
- 用完之后需要赶紧关闭,否则资源被占用!
边栏推荐
猜你喜欢

Solve the problem that MySQL cannot insert Chinese data

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

三种方案解决:npm WARN config global --global, --local are deprecated. Use --location=global instead.

打开微信客服

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

【Day_11 0506】 最近公共祖先

Leetcode74. Search 2D Matrix

What is the JVM runtime data area and the JMM memory model

B011 - 51-based multifunctional fingerprint smart lock

explain 各字段介绍
随机推荐
三维空间中点的插值
Live chat system technology (8) : vivo live IM message module architecture practice in the system
B011 - 51-based multifunctional fingerprint smart lock
opencv syntax Mat type summary
【Error】Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘concat’)
塔防海岸线用户协议
Topology Parts Disassembly 3D Visualization Solution
Three solutions: npm WARN config global --global, --local are deprecated. Use --location=global instead.
Leetcode75. Color Classification
CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) 题解
BITS Pilani|SAC-AP:基于 Soft Actor Critic 的深度强化学习用于警报优先级
用VS2013编译带boost库程序时提示 fatal error C1001: 编译器中发生内部错误
tooltip 控件
golang json 返回空值
请你说说多线程
解决MySQL插入不了中文数据问题
OpenCV安装、QT、VS配置项目设置
WinRAR | 将多个安装程序生成一个安装程序
SQL函数 TO_DATE(二)
Leetcode71. Simplified Paths