【问题标题】:c3po configuration and mysql aborted connectionsc3po 配置和 mysql 中止连接
【发布时间】:2016-12-20 16:49:16
【问题描述】:

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

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

可能是因为 hibernate.c3p0.idle_test_periods 高于 hibernate.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

【问题讨论】:

    标签: java mysql c3p0


    【解决方案1】:

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

    hibernate.c3p0.testConnectionOnCheckout=true
    

    或者,请参阅c3p0 docs

    【讨论】:

    • 谢谢,但我不确定它与我的问题有何关系?添加testConnectionOnCheckout=true 会降低性能?
    • 您的应用程序看到陈旧的连接 - 不再有效的连接 + 在尝试与 RDBMS 通信时产生错误。如果您将 c3p0 配置为测试连接,则池将检测这些陈旧的连接并在您的应用程序看到它们之前将其消除。 testConnectionOnCheckout=true 确实会带来性能成本,但只要您使用最新的 JDBC 驱动程序,成本就会适中[它将使用快速 Connection.isValid() 方法]。如果结帐时测试的成本不可接受,您可以使用签入测试和空闲测试。但你可能不需要
    • “您可以在签入和空闲测试中使用测试”是什么意思?
    • 请参阅文档中的第 3 步绿色框(链接在上面的答案中)。但只要您使用的是最新的 JDBC 驱动程序和最新的 c3p0 (0.9.5.2),这可能不值得麻烦,testConnectionOnCheckout=true 可能没问题。
    猜你喜欢
    • 2013-01-10
    • 2014-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-25
    • 2018-11-21
    • 1970-01-01
    • 2018-09-09
    相关资源
    最近更新 更多