当前位置:网站首页>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!
边栏推荐
- 【Day_12 0507】二进制插入
- 暑假第二周总结博客
- 一加OnePlus 10RT出现在Geekbench上 产品发布似乎也已临近
- B005 - STC8 based single chip microcomputer intelligent street light control system
- Zabbix6.0钉钉机器人告警
- Friends who want to use the database anytime, anywhere and as you like, all attention!
- explain 各字段介绍
- Leetcode75. 颜色分类
- AIOps智能运维的领跑者擎创科技正式入驻InfoQ 写作社区!
- 想随时、随地、随心使用数据库的朋友们,全体注意!
猜你喜欢

Leetcode74. Search 2D Matrix

Prometheus的Recording rules实践

MySQL数据库————存储过程和函数

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

Zabbix6.0 DingTalk robot alarm

【报错】Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘concat‘)

食品安全 | 新鲜食品vs速食食品,哪一种是你的菜?

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

QT基础功能,信号、槽

Leetcode73. 矩阵置零
随机推荐
How to build a CMDB driven by consumption scenarios?
MySQL 45 Talk | 09 How to choose common index and unique index?
Industry Salon Phase II丨How to enable chemical companies to reduce costs and increase efficiency through supply chain digital business collaboration?
opencv real-time face detection
B011 - 51-based multifunctional fingerprint smart lock
食品安全 | 新鲜食品vs速食食品,哪一种是你的菜?
云原生全景图详解
What is the JVM runtime data area and the JMM memory model
钳形万用表使用方法,如何测量电压、电流、电阻?
WinRAR | 将多个安装程序生成一个安装程序
深入浅出Flask PIN
将ENS域名转化为音乐需要几步?
塔防海岸线用户协议
QT basic functions, signals, slots
BITS Pilani|SAC-AP:基于 Soft Actor Critic 的深度强化学习用于警报优先级
突破性能天花板!亚信数据库支撑 10 多亿用户,峰值每秒百万交易
打开微信客服
B002 - 基于嵌入式的老人定位追踪监测仪
OpenCV installation, QT, VS configuration project settings
How many steps does it take to convert an ENS domain name into music?