c3p0 java.sql.SQLException: Connection is invalid

异常信息:

BasicResourcePool: An idle resource is broken and will be purged.
java.sql.SQLException: Connection is invalid
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1.testPooledConnection(C3P0PooledConnectionPool.java:196)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1.refurbishIdleResource(C3P0PooledConnectionPool.java:136)
at com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask.run(BasicResourcePool.java:1394)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:368)
在网上找了下,很多说连接池有问题,给出N种解决方案.
不解之下换google搜索,直接命中靶心:
SoftSlate Commerce uses the c3p0 library to handle connection pooling, and these errors are from c3p0 as it tests idle connections to see that they are valid.
In your hibernate.properties file, you can define the c3p0 "idle_test_period", which is the interval of seconds c3p0 will test all idle connections. By default it's set to 600, or 10 minutes, and you'll see in the log that the messages are in groups 10 minutes apart.
What is the purpose of testing idle connections? Strictly speaking I don't believe it's necessary because (at least with SoftSlate's default configuration) connections are always tested first before they are checked out of the pool. (You'll see this happens because of the "c3p0.testConnectionOnCheckout=true" setting in the c3p0.properties file.) However in high-volume sites where performance is a big issue you might like to turn off of the connection testing on checkout and instead rely on the interval testing defined by "idle_test_period".

As to why your idle connections are being broken, I am not sure but my guess is the database itself has a connection timeout setting, and the connections are timing out with the underlying database. So when c3p0 tests them, it finds they are broken.

Long story short, I don't think you have to worry about this as long as you test connections as they are being checked out with the "c3p0.testConnectionOnCheckout=true" setting in the c3p0.properties file.

也就是说这不是问题,仅仅是一个定时的测试连接是否正常的程序,可以在连接池的配置文件中禁掉:

  1. <property name="testConnectionOnCheckout">   
  2.        <value>true</value>   
  3. </property>  
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值