# Set a connection to wait 8 hours in idle status.
wait_timeout = 86400
# How long to keep unused connections around(in seconds)
# Note: MySQL times out idle connections after 8 hours(28,800 seconds)
# so ensure this value is below MySQL idle timeout
cpool.maxIdleTime=25200
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="maxIdleTime" value="${cpool.maxIdleTime}" />
<!-- other properties -->
</bean># Prevent MySQL raise exception after a long idle time
cpool.preferredTestQuery=‘SELECT 1‘
cpool.idleConnectionTestPeriod=18000
cpool.testConnectionOnCheckout=true
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="preferredTestQuery"
value="${cpool.preferredTestQuery}" />
<property name="idleConnectionTestPeriod"
value="${cpool.idleConnectionTestPeriod}" />
<property name="testConnectionOnCheckout"
value="${cpool.testConnectionOnCheckout}" />
<!-- other properties -->
</bean>
#!/bin/awk
BEGIN {
FS="=";
}
{
if (NF == 2) {
if ((x=index($1, ".")) > 0) {
property_name = substr($1, x+1, length($1));
} else {
property_name = $1;
}
printf("<property name="%s" value="${%s}"/> ", property_name, $1);
}
}解决 c3p0 和 MySQL 集成情况下,连接长时间闲置后重新使用时报错的问题
原文:http://www.blogjava.net/stevenjohn/archive/2014/12/15/421421.html