用ssh框架做了个小项目,用c3p0做连接池,用的是Mysql 5.1.x ,现问题如下:

2025-03-24 20:14:20
推荐回答(4个)
回答1:

关键你给的分太少!如下是上线达1年,稳定运行的配置。
---------------------------------------------------------、
属性文件
c3p0.driverClass=com.mysql.jdbc.Driver
c3p0.user=root
c3p0.password=edwin
c3p0.jdbcUrl=jdbc\:mysql\://192.168.1.123\:3306/edwin?useUnicode\=true&characterEncoding\=utf-8
c3p0.minPoolSize = 1
c3p0.maxPoolSize = 50
c3p0.initialPoolSize = 1
c3p0.maxIdleTime = 25000
c3p0.acquireIncrement = 1
c3p0.acquireRetryAttempts = 30
c3p0.acquireRetryDelay = 1000
c3p0.testConnectionOnCheckin = true
c3p0.automaticTestTable = t_c3p0
c3p0.idleConnectionTestPeriod = 18000
c3p0.checkoutTimeout=5000
---------------------------------------------------------
spring配置


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-autowire="byName" default-lazy-init="false">


classpath:com/edwin/db/config/c3p0.properties




${c3p0.driverClass}


${c3p0.jdbcUrl}


${c3p0.user}


${c3p0.password}


${c3p0.minPoolSize}


${c3p0.maxPoolSize}


${c3p0.initialPoolSize}


${c3p0.maxIdleTime}


${c3p0.acquireIncrement}


${c3p0.acquireRetryAttempts}


${c3p0.acquireRetryDelay}


${c3p0.testConnectionOnCheckin}


${c3p0.automaticTestTable}


${c3p0.idleConnectionTestPeriod}


${c3p0.checkoutTimeout}





-------------------------------------------------
t_c3p0 就是一个测试表!

回答2:

解决的方法有3种:

增加wait_timeout的时间。
减少Connection pools中connection的lifetime。
测试Connection pools中connection的有效性。
C3P0增加以下配置信息:

//获取connnection时测试是否有效
testConnectionOnCheckin = true
//自动测试的table名称,可以自己建个空表来做测试
automaticTestTable=C3P0TestTable
//设置时间必须少于MySQl wait_timeout
idleConnectionTestPeriod = 18000
//设置时间必须少于MySQl wait_timeout
maxIdleTime = 25000
//开启连接检查
testConnectionOnCheckout = true

回答3:

0
0
不能用 0

回答4:

关注