私は grails アプリを使用していますが、アクティビティが頻繁に発生しますが、非アクティブな期間が数時間から一晩続くことがよくあります。朝の最初のユーザーが次のような例外を受け取ることに気付きました。これは、プール内の接続が古くなり、MYSql データベースが接続を閉じたためだと思います。
Connector/J 接続プロパティ 'autoReconnect=true' を使用するのが良い考えかどうか (そして、接続が復元されてもクライアントが例外を受け取るかどうか)、または設定するかどうかについて、Google で矛盾する情報を見つけました。アイドル状態の接続を定期的に削除または更新したり、借用をテストしたりするその他のプロパティ。Grails はその下で DBCP を使用します。私は現在、以下のように単純な構成を持っており、長い非アクティブ期間の後にプールから取得された接続が有効であり、閉じられていないことを確認する最善の方法についての回答を探しています。
dataSource {
pooled = true
dbCreate = "update"
url = "jdbc:mysql://my.ip.address:3306/databasename"
driverClassName = "com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
username = "****"
password = "****"
properties {
//what should I add here?
}
}
例外
2012-06-20 08:40:55,150 [http-bio-8443-exec-1] ERROR transaction.JDBCTransaction - JDBC begin failed
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 64,129,968 milliseconds ago. The last packet sent successfully to the server was 64,129,968 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.
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3851)
...... Lots more .......
Caused by: java.sql.SQLException: Already closed.
at org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:114)