jdbc中自带MySQL连接池实例分析
引言下面是com.mysql.cj.jdbc.MysqlConnectionPoolDataSource使用实践,比较简单,API倒是挺多的,但是大多数都用不到。packagecom.funtest.groovytestimportcom.funtester.frame.SourceCodeimportcom.mysql.cj.jdbc.MysqlConnectionPoolDataSourceclassMysqlPoolTeextendsSourceCode{publicstaticvoidmain(S
引言
下面是com.mysql.cj.jdbc.MysqlConnectionPoolDataSource使用实践,比较简单,API 倒是挺多的,但是大多数都用不到。
package com.funtest.groovytest
import com.funtester.frame.SourceCode
import com.mysql.cj.jdbc.MysqlConnectionPoolDataSource
class MysqlPoolTe extends SourceCode {
public static void main(String[] args) {
def query = "select * from testers limit 2;"
def source = new MysqlConnectionPoolDataSource()
source.setServerName("localhost")
source.setPort(3306)
source.setUser("root")
source.setPassword("root123456")
source.setDatabaseName("funtester")
source.setAllowMultiQueries(true)
def connection = source.getPooledConnection()
def statement = connection.getConnection().createStatement()
while (true) {
sleep(1)
def query = statement.executeQuery(query)
while (query.next()) {
output query.getString("name")
}
}
}
}这里有个很容易的坑,就是有个setURL()还有一个setUrl(),其实这两个没有任何区别,我只能说可能为了兼容旧版本把。还有就是设置了 URL 之后,好像 database 设置不起作用了,也是妙明感觉设计真糟心,所以在上面的案例中我也没有用到这俩方法。
下面是我的测试结果,如图所示创建了超级多的线程,但是一直连接的只有很少。大概是经过几秒钟就会被回收一次,但是总创建数依旧非常高。

Windows 10 是一款微软推出的经典操作系统,拥有硬件兼容性与多任务处理能力。它更偏向把系统状态查看和常用调节动作放在一起,适合需要持续观察和微调设备状态的场景。
极度公式是一款跨平台专业LaTeX公式识别编辑软件,支持OCR公式识别和多平台编辑。和使用说明,避免使用,享受完整功能与稳定支持。做扫描整理、文字提取和表格转换时,它能把识别后的处理步骤接得更顺,资料录入这类场景会省下不少时间。
















