3

有一个 Grails2.2/Hibernate/Tomcat7/MySQL5.5 网络服务器。在几个小时没有 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"/>
4

2 回答 2

2

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

<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>
于 2013-01-31T12:34:30.200 回答
0

c3p0 没有在我的应用程序中使用,所以我最终告诉我的数据源首先验证数据库连接:

<Resource ...
   validationQuery="SELECT 1"
   testOnBorrow="true"/>
于 2013-02-13T08:02:25.093 回答