有一个Grails2.2 / Hibernate / Tomcat7 / MySQL5.5 Web服务器。在没有Web客户端请求它几个小时之后,对它的第一个请求失败如下。 (事实上,它每天早上都会发生。)正确处理任何顺序请求。
我向?autoReconnect=true
指示了MySQL驱动程序,但它没有帮助。
下面可以注意到回滚,但我没有直接从我的代码中调用它。相反,它会在长时间暂停后尝试保留对象时隐式发生。
有任何想法可以解决这个问题吗?
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"/>
答案 0 :(得分:2)
尝试将以下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>
答案 1 :(得分:0)
我的应用程序中没有使用c3p0所以我最终告诉我的数据源首先验证数据库连接:
<Resource ...
validationQuery="SELECT 1"
testOnBorrow="true"/>