当前位置:网站首页>自定义MySQL连接池
自定义MySQL连接池
2022-06-28 12:39:00 【51CTO】
最近在学习了通用池化框架commons-pool2实践之后,再HTTP性能测试中进行了实践,结果出乎意料,对于性能提升没啥卵用。经过我自己的本地测试,性能也是足够好的。
后来我仔细想了想,原来是我用错地方了。本来想自己写一个Redis的连接池的没想到,jedis的连接池本身就是commons-pool2开发的,让我有点意外,看来想的是一样的。commons-pool2用来做连接池是非常不错的。
我仔细找了找,发现还缺一个本地的MySQL连接池,而不是springboot那样需要启动一个服务才行。当然应该也是有的,不过我非常想自己写一个然后进行各类测试,所以也没有仔细找。
可池化对象
首先,我们需要一个可池化对象,这里我选用了com.funtester.db.mysql.FunMySql,这是一个我自己写的单链接的MySQL对象。我计划用这个作为基础可池化对象。
池化工厂
相对连接,创建com.funtester.db.mysql.FunMySql的时候,顺便一起初始化MySQL连接。然后再com.funtester.db.mysql.MysqlPool.FunTester#destroyObject的时候进行连接的回收。
对象池
这里显得有些冗余,后面再使用过程中,我会继续优化。通过创建一个com.funtester.db.mysql.MysqlPool对象,获取一个com.funtester.db.mysql.FunMySql对象池。
API封装
自从学习了Go语言的gorm框架和Redis框架,我发现其实不用把池化相关信息不用暴露出来,直接封装原始的API,暴露给用户使用,这样用户就不用关心连接的回收问题了。
BUG挖掘机·性能征服者·头顶锅盖
边栏推荐
- 【Unity编辑器扩展基础】、EditorGUILayout(二)
- 杰理之wif 干扰蓝牙【篇】
- I²C、SMBus、PMBus关系
- What is the difference between internal oscillator, passive crystal oscillator and active crystal oscillator?
- unity发布 webgl在手机端 inputfield唤醒键盘输入
- Unity Editor Extension Foundation, editorguilayout (III)
- C语言 sprintf函数使用详解
- 设置Canvas的 overrideSorting不生效
- 攻防世界新手入门hello_pwn
- 30套JSP网站源代码合集「建议收藏」
猜你喜欢

易观分析《2022年中国银行业隐私计算平台供应商实力矩阵分析》研究报告正式启动

最新!基于Open3D的点云处理入门与实战教程

Unity Editor Extension Foundation, editorguilayout (II)

Login interface accesses and clears the token

ASP.NET CORE Study08

洛谷_P1303 A*B Problem_高精度计算

如何在Microsoft Exchange 2010中安装SSL证书
![[unity Editor Extension Foundation], editorguilayout (I)](/img/f2/42413a4135fd6181bf311b685504b2.png)
[unity Editor Extension Foundation], editorguilayout (I)

吐血推荐17个提升开发效率的“轮子”

Bytev builds a dynamic digital twin network security platform -- helping network security development
随机推荐
【MySQL从入门到精通】【高级篇】(三)MySQL用户的创建_修改_删除以及密码的设置
模板_大整数乘法
为什么CAD导出PDF没有颜色
【Unity编辑器扩展基础】、EditorGUILayout (一)
UGUI使用小技巧(六)Unity实现字符串竖行显示
【Unity编辑器扩展基础】、EditorGUILayout (三)
Bytev builds a dynamic digital twin network security platform -- helping network security development
百度APP 基于Pipeline as Code的持续集成实践
Mathematical principle derivation of structured light phase shift method + multifrequency heterodyne
真正的学懂三极管入门篇(经典)「建议收藏」
What are the common modes of financial products in 2022?
newest! Introduction and practical tutorial of point cloud processing based on open3d
Continuous integration practice of Baidu app based on pipeline as code
Why does CAD export PDF have no color
小白创业做电商,选对商城系统很重要!
Jerry's wif interferes with Bluetooth [chapter]
Jerry's wif interferes with Bluetooth [chapter]
几百行代码实现一个 JSON 解析器
【编解码】从零开始写H264解码器(1) 总纲
关于字符串转换的一些小技巧