gpt4 book ai didi

数小时未访问服务器后出现 MySQLNonTransientConnectionException

转载 作者:可可西里 更新时间:2023-11-01 08:35:20 26 4
gpt4 key购买 nike

有Grails2.2/Hibernate/Tomcat7/MySQL5.5 web服务器。在几个小时内没有 Web 客户端请求它之后,对它的第一个请求失败如下。 (事实上​​ ,它每天早上都会发生。)任何顺序请求都得到正确处理。

我指示 MySQL 驱动程序 ?autoReconnect=true 但它没有帮助。

回滚可以在下面看到,但我没有直接从我的代码中调用它。相反,它会在长时间暂停后尝试保留对象时隐式发生。

有什么办法可以解决这个问题吗?

Error 500: Executing action [actionName] of controller [MyController] caused exception: Runtime error executing action
Servlet: grails
URI: /appname/grails/appName/actionName.dispatch
Exception Message: Communications link failure during rollback(). Transaction resolution unknown.
Caused by: Communications link failure during rollback(). Transaction resolution unknown.
Class: MyController
At Line: [139]
Code Snippet:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during rollback(). Transaction resolution unknown.
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1014)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.ConnectionImpl.rollback(ConnectionImpl.java:4808)
at org.apache.commons.dbcp.DelegatingConnection.rollback(DelegatingConnection.java:368)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.rollback(PoolingDataSource.java:323)
at MyController.logRequest(...)
...
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)

Tomcat 的 context.xml:

<Resource name="jdbc/JNDI_NAME" auth="Container"
type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/dbname?autoReconnect=true"
username="xxx" password="xxx" maxActive="20" maxIdle="10"
removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"
maxWait="-1"/>

最佳答案

尝试将以下 c3po 配置添加到您的 hibernate.cfg.xml 文件中。那应该有帮助;见this .

<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">300</property>
<property name="hibernate.c3p0.timeout">5000</property>
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.acquireRetryAttempts">3</property>
<property name="hibernate.c3p0.acquireRetryDelay">1000</property>

关于数小时未访问服务器后出现 MySQLNonTransientConnectionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14598050/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com