【问题标题】:The last packet successfully received from the server was 109,253 milliseconds ago从服务器成功接收到的最后一个数据包是 109,253 毫秒前
【发布时间】:2015-01-18 00:10:27
【问题描述】:

我知道这个问题已经被问过并回答了很多次,但没有任何解决方案可以解决这个问题。

在生产中,我收到类似这样的错误“从服务器成功接收的最后一个数据包是 109,253 毫秒前。”。所以我选择了c3p0,并在persistence.xml中进行了以下配置,并在my.cnf中将mysql的属性设置为wait_timeout=60并在设置下使用。

<properties>
            <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
            <property name="hibernate.show_sql" value="true"></property>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost/Test"/>
            <property name="hibernate.connection.user" value="****" />
            <property name="hibernate.connection.password" value="***" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.hibernate.auto_close_session" value="true" />

            <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/> 
            <property name="hibernate.c3p0.acquire_increment" value="1"/>
            <property name="hibernate.c3p0.idle_test_period" value="10"/>
            <property name="hibernate.c3p0.min_size" value ="5"/>
            <property name="hibernate.c3p0.max_size" value="20"/>
            <property name="hibernate.c3p0.timeout" value="50"/>
            <property name="hibernate.c3p0.preferredTestQuery" value="select 1"/>
            <property name="hibernate.c3p0.testConnectionOnCheckout" value="true"/>             
    </properties>

即使在我看到的日志中

Nov 20, 2014 1:06:35 PM com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.2.1 [built 20-March-2013 10:47:27 +0000; debug? true; trace: 10]
Nov 20, 2014 1:06:35 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@1e8ef9ca [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@1f5f812 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> z8kfsx951kn0e3017dmiyd|24ba9ccb, idleConnectionTestPeriod -> 10, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 50, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 75, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@fa4d1db0 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> z8kfsx951kn0e3017dmiyd|29c3481b, jdbcUrl -> jdbc:mysql://localhost/DAL, properties -> {user=******, password=******} ], preferredTestQuery -> select 1, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> true, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> z8kfsx951kn0e3017dmiyd|126d8fa6, numHelperThreads -> 3 ]

但仍然遇到同样的问题。我尝试了很多事情,甚至在类路径中制作了 hibrenate.properties,因为我读到了一些属性,例如 preferredTestQuery 需要在属性文件中设置,所以我在类路径中创建了一个具有以下属性的属性文件

hibernate.c3p0.idle_test_period=10
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=75
hibernate.c3p0.max_statements=75
hibernate.c3p0.timeout=50
hibernate.c3p0.preferredTestQuery=select 1
hibernate.c3p0.testConnectionOnCheckout=true

我可以在日志中看到甚至加载属性

org.hibernate.cfg.Environment - HHH000205: Loaded properties from resource hibernate.properties: {hibernate.c3p0.testConnectionOnCheckout=true, hibernate.c3p0.timeout=50, hibernate.c3p0.min_size=5, hibernate.c3p0.max_size=75, hibernate.bytecode.use_reflection_optimizer=false, hibernate.c3p0.preferredTestQuery=select 1, hibernate.c3p0.max_statements=75, hibernate.c3p0.idle_test_period=10

但如果我在一分钟后尝试仍然会得到同样的错误。我无法理解我错过了什么。请告诉我?

【问题讨论】:

    标签: hibernate jpa c3p0


    【解决方案1】:

    我有同样的问题,解决方案是为mysql添加属性validationQuery值SELECT 1

    【讨论】:

      【解决方案2】:

      您的应用程序可能会保持连接打开,而不是立即将它们返回到池中。

      要对此进行测试,请尝试设置 unreturnedConnectionTimeout 和 debugUnreturnedConnectionStackTraces。详情请见here。

      然后检查您的日志。如果您的连接超时未返回,请查看打开连接的代码路径的记录堆栈跟踪,并修改您的应用程序代码以及时可靠地关闭()这些连接,并根据需要从数据源获取连接,并且只是-及时。

      【讨论】:

      • 是的 debugUnreturnedConnectionStackTraces 帮助了我。连接没有正确关闭
      • 我使用的是 Injecting private EntityManager em;在它的位置,我使用了 Injected private Provider entityManagerProvider;它解决了我的问题
      猜你喜欢
      • 2016-03-23
      • 1970-01-01
      • 2022-01-07
      • 2018-04-18
      • 2018-01-05
      • 2016-04-01
      • 2020-01-13
      • 2013-01-11
      • 2012-11-20
      相关资源
      最近更新 更多