c3po 配置和 mysql 中止连接

c3po configuration and mysql aborted connections

我在数据库端收到了很多 Aborted connection 消息 - [Note] Aborted connection 11043 to db: 'mysql' user: 'mysql' host: Got an error reading communication packets

我对应用程序和数据库没有任何问题,但我想知道为什么我会收到这些消息。

难道是因为hibernate.c3p0.idle_test_periodshibernate.c3p0.timeout高?

这是休眠配置文件:

hibernate.id.new_generator_mappings=false
hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
hibernate.format_sql=false
hibernate.max_fetch_depth=3
hibernate.show_sql=false
hibernate.use_sql_comments=false
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.dialect=com.p.db.pMySqlDialect
hibernate.connection.release_mode=after_transaction
hibernate.c3p0.acquire_increment=1
hibernate.c3p0.idle_test_period=10
hibernate.c3p0.timeout=0
hibernate.c3p0.max_statements=0
hibernate.c3p0.min_size=3
hibernate.c3p0.max_size=400
hibernate.c3p0.preferredTestQuery=select 1
hibernate.c3p0.acquireRetryAttempts=5
hibernate.c3p0.acquireRetryDelay=1000
hibernate.c3p0.breakAfterAcquireFailure=false
hibernate.c3p0.testConnectionOnCheckin=false
hibernate.c3p0.testConnectionOnCheckout=false

数据库访问日志:

DEBUG [C3P0PooledConnectionPoolManager[identityToken->z8kfsx9l7vpkfr1egte0l|cf2bf60]-HelperThread-#2] [UID:, MSG_ID:] [com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool] <Test of PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@41d8a248] on IDLE CHECK has SUCCEEDED.>
DEBUG [C3P0PooledConnectionPoolManager[identityToken->z8kfsx9l7vpkfr1egte0l|cf2bf60]-HelperThread-#1] [UID:, MSG_ID:] [com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool] <Testing PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@7d10203] on IDLE CHECK.>
DEBUG [C3P0PooledConnectionPoolManager[identityToken->z8kfsx9l7vpkfr1egte0l|cf2bf60]-HelperThread-#0] [UID:, MSG_ID:] [com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool] <Testing PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@264d3257] on IDLE CHECK.>
DEBUG [C3P0PooledConnectionPoolManager[identityToken->z8kfsx9l7vpkfr1egte0l|cf2bf60]-HelperThread-#2] [UID:, MSG_ID:] [com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool] <Testing PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@ea7e8fb] on IDLE CHECK.>
DEBUG [C3P0PooledConnectionPoolManager[identityToken->z8kfsx9l7vpkfr1egte0l|cf2bf60]-HelperThread-#0] [UID:, MSG_ID:] [com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool] <Test of PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@264d3257] on IDLE CHECK has SUCCEEDED.>
DEBUG [C3P0PooledConnectionPoolManager[identityToken->z8kfsx9l7vpkfr1egte0l|cf2bf60]-HelperThread-#1] [UID:, MSG_ID:] [com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool] <Test of PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@7d10203] on IDLE CHECK has SUCCEEDED.>
DEBUG [C3P0PooledConnectionPoolManager[identityToken->z8kfsx9l7vpkfr1egte0l|cf2bf60]-HelperThread-#0] [UID:, MSG_ID:] [com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool] <Testing PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@2cb753e7] on IDLE CHECK.>
DEBUG [C3P0PooledConnectionPoolManager[identityToken->z8kfsx9l7vpkfr1egte0l|cf2bf60]-HelperThread-#2] [UID:, MSG_ID:] [com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool] <Test of PooledConnection

连接最终会失效。请配置一些连接测试。最简单的做法就是修改您的配置,以便

hibernate.c3p0.testConnectionOnCheckout=true

或者,参见 c3p0 docs