Grails和MySQL连接异常

Grails和MySQL连接异常,mysql,tomcat,grails,Mysql,Tomcat,Grails,我有一个正在生产的grails应用程序。今天早上,我被提醒服务器没有解析。Tomcat旋转着,旋转着。我研究了一下,它似乎与MySQL有关,导致连接在8小时不活动后超时。有类似问题的人。但是,所有这些人都提到,如果他们再次点击服务器,连接就会刷新。对我来说,网站完全关闭了,Tomcat没有回应。这听起来像是在玩什么游戏吗 Tomcat日志中的最后一个异常 2011-Aug-30 23:58:43,283 [TP-Processor19] org.hibernate.util.JDBCExcept

我有一个正在生产的grails应用程序。今天早上,我被提醒服务器没有解析。Tomcat旋转着,旋转着。我研究了一下,它似乎与MySQL有关,导致连接在8小时不活动后超时。有类似问题的人。但是,所有这些人都提到,如果他们再次点击服务器,连接就会刷新。对我来说,网站完全关闭了,Tomcat没有回应。这听起来像是在玩什么游戏吗

Tomcat日志中的最后一个异常

2011-Aug-30 23:58:43,283 [TP-Processor19] org.hibernate.util.JDBCExceptionReporter
 ERROR The last packet successfully received from the server was 37,118,147 milliseconds ago.  The last packet sent successfully to the server was 37,122,138 milliseconds ago. \
is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing \
the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
2011-Aug-30 23:58:43,290 [TP-Processor19] org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver
 ERROR Exception occurred when processing request: [GET] /picks/ncaafb
Stacktrace follows:
java.net.SocketException: Connection timed out
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3302)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1940)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)
        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2275)
  at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2275)
        at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
        at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
        at sportsdb.Season.getCurrentNCAAFootballSeason(Season.groovy:93)
        at PicksController$_closure2.doCall(PicksController.groovy:60)
        at PicksController$_closure2.doCall(PicksController.groovy)
        at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
        at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
        at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:774)
        at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:703)
        at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:896)
        at java.lang.Thread.run(Thread.java:662)
2011-Aug-30 23:58:43,315 [TP-Processor19] org.hibernate.util.JDBCExceptionReporter
 ERROR Already closed.
2011-Aug-30 23:58:43,315 [TP-Processor19] org.hibernate.util.JDBCExceptionReporter
 ERROR Already closed.
2011-Aug-30 23:58:43,316 [TP-Processor19] org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet
 ERROR HandlerInterceptor.afterCompletion threw exception
org.hibernate.exception.GenericJDBCException: Cannot release connection
        at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
        at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
        at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:774)
        at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:703)
        at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:896)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.sql.SQLException: Already closed.
        at org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:114)
        at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:191)
        at $Proxy7.close(Unknown Source)
        ... 6 more

我的计划是实现上面链接中提到的解决方案,但我想确保没有其他明显可疑的事情发生,因为我们有一个稍微不同的结果,它们的连接正在刷新,而我的连接没有。

如果您在数据源(如testOnBorrow)上使用Tomcat JNDI数据源。如果验证失败,将从池中删除连接。测试连接会带来一些性能开销,但它应该可以解决这样的问题。如果将minIdle/maxIdle设置为高,则可以解释为什么在重新连接时仍会遇到此问题,并为其他人修复此问题

如果您在数据源上使用Tomcat JNDI数据源,例如TestOnFrook。如果验证失败,将从池中删除连接。测试连接会带来一些性能开销,但它应该可以解决这样的问题。如果将minIdle/maxIdle设置为高,则可以解释为什么在重新连接时仍会遇到此问题,并为其他人修复此问题

我想这样做可以修复我想这样做可以修复我正在使用MySQL ConnectorJ。我能不能用ConnectorJ在这里设置参数大纲?:我通常使用JNDI在Tomcat上配置数据源,这是我比较熟悉的。但是仔细看一下刚才的,当您在DataSource.groovy中定义DBCP BasicDataSource属性时,或者在resources.groovy中单独定义它时,您可以使用相同的DBCP BasicDataSource属性。我能不能用ConnectorJ在这里设置参数大纲?:我通常使用JNDI在Tomcat上配置数据源,这是我比较熟悉的。但仔细看一下刚才的,当您在DataSource.groovy中或在resources.groovy中单独定义DBCP BasicDataSource属性时,可以使用相同的DBCP BasicDataSource属性。