我正在使用复制驱动程序com.mysql.jdbc.ReplicationDriver
并使用 jdbc 配置我的连接
jdbc.de.url=jdbc:mysql:replication://master:3306,slave:3306/lieferando_de?zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8&tcpKeepAlive=true
c3p0 配置为每 30 秒测试一次池连接
<bean id="basisDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" abstract="true">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="30" />
<property name="maxIdleTime" value="14400" />
<property name="maxConnectionAge" value="14400" />
<property name="testConnectionOnCheckout" value="false" />
<property name="idleConnectionTestPeriod" value="30" />
<property name="preferredTestQuery" value="SELECT 1" />
</bean>
但我只看到正在测试的主人
[DEBUG] 25.06.2013 13:29:30 com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0 Testing PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@6b6a16ae] on IDLE CHECK.
[DEBUG] 25.06.2013 13:29:30 com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1 Testing PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@5c219c51] on IDLE CHECK.
[DEBUG] 25.06.2013 13:29:30 com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2 Testing PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@7e350225] on IDLE CHECK.
[DEBUG] 25.06.2013 13:29:30 com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1 Test of PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@5c219c51] on IDLE CHECK has SUCCEEDED.
[DEBUG] 25.06.2013 13:29:30 com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1 Testing PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@602f892f] on IDLE CHECK.
[DEBUG] 25.06.2013 13:29:30 com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0 Test of PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@6b6a16ae] on IDLE CHECK has SUCCEEDED.
[DEBUG] 25.06.2013 13:29:30 com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0 Testing PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@7deb41d6] on IDLE CHECK.
[DEBUG] 25.06.2013 13:29:30 com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2 Test of PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@7e350225] on IDLE CHECK has SUCCEEDED.
[DEBUG] 25.06.2013 13:29:30 com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1 Test of PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@602f892f] on IDLE CHECK has SUCCEEDED.
[DEBUG] 25.06.2013 13:29:30 com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0 Test of PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@7deb41d6] on IDLE CHECK has SUCCEEDED.
最初,主从连接是打开的,计数为 5
macbookpro-533f:~ mlaug$ netstat -nat | grep 3306
tcp4 0 0 10.10.14.181.57215 slave.3306 ESTABLISHED
tcp4 0 0 10.10.14.181.57214 slave.3306 ESTABLISHED
tcp4 0 0 10.10.14.181.57213 master.3306 ESTABLISHED
tcp4 0 0 10.10.14.181.57212 master.3306 ESTABLISHED
tcp4 0 0 10.10.14.181.57211 slave.3306 ESTABLISHED
tcp4 0 0 10.10.14.181.57209 slave.3306 ESTABLISHED
tcp4 0 0 10.10.14.181.57210 slave.3306 ESTABLISHED
tcp4 0 0 10.10.14.181.57208 master.3306 ESTABLISHED
tcp4 0 0 10.10.14.181.57207 master.3306 ESTABLISHED
tcp4 0 0 10.10.14.181.57206 master.3306 ESTABLISHED
但是从连接在 5 分钟后消失,导致应用程序抛出Broken Pipe Exception
.
如何配置c3p0
以测试从属连接?