2011-08-31 61 views
2

我有一個現在正在生產的grails應用程序。今天早上,我被警告服務器沒有解決這個事實。雄貓正在旋轉和旋轉。我研究過,看起來它與MySQL有關,導致連接在閒置8小時後超時。 I have found examples on stackoverflow有類似問題的人。但是,所有這些人都提到,如果他們再次點擊服務器並刷新連接。對我而言,該網站完全停止,Tomcat不會迴應。這聽起來像其他東西可以在這裏玩嗎?Grails和MySQL連接異常

在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 

我的計劃是要實現上面的鏈接中提到的解決方案,但我想,以確保沒有其他明顯的魚腥味是怎麼回事,因爲我們有一個稍微不同的結果(他們的聯繫令人耳目一新,而我的不在)。

+0

我想這樣做http://stackoverflow.com/questions/2740987/mysql-connection-timeout-issue-grails-application-on-tomcat-using-hibernate-並且將修復它 – hvgotcodes

回答

0

如果您在數據源(如testOnBorrow)上使用Tomcat JNDI數據源look at some of the parameters you can set。如果驗證失敗,連接將從池中刪除。測試連接會帶來一些性能開銷,但它應該解決這樣的問題。如果將minIdle/maxIdle設置爲高,這將解釋爲什麼您在重新連接時仍然會遇到問題,併爲其他人修復此問題。

+0

我正在使用MySQL ConnectorJ。我能否在這裏用ConnectorJ設置參數大綱:http://stackoverflow.com/questions/2740987/mysql-connection-timeout-issue-grails-application-on-tomcat-using-hibernate-and/2755376#2755376 – skaz

+1

我通常使用JNDI在Tomcat上配置數據源,這就是我更熟悉的內容。但是,現在仔細查看[Grails doc](http://grails.org/doc/latest/guide/3.%20Configuration.html#3.3%20The%20DataSource),您可以在您使用相同的DBCP BasicDataSource屬性在DataSource.groovy中定義它(或在resources.groovy中單獨定義)。 – proflux