关键你给的分太少!如下是上线达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: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">
-------------------------------------------------
t_c3p0 就是一个测试表!
解决的方法有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
不能用 0
关注