Grails 2.3.0和mysql连接超时 [英] Grails 2.3.0 and mysql connection timeout

查看:122
本文介绍了Grails 2.3.0和mysql连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用这个配置连接到mysql数据库的Grails 2.2.3应用程序:

I have a Grails 2.2.3 application using this configuration to connect to a mysql database:

 production {
    dataSource {
        dbCreate = "update" // one of 'create', 'create-drop','update'
        url = "jdbc:mysql://localhost/database?autoReconnect=true"

        pooled = true
        properties {
            maxActive = 50
            maxIdle = 25
            minIdle = 5
            initialSize = 5
            minEvictableIdleTimeMillis = 1800000
            timeBetweenEvictionRunsMillis = 1800000
            maxWait = 10000

        }


    }

}

升级到Grails 2.3.0后,此工作停止工作,并且在应用程序的周末不活动之后,我得到以下异常:

After upgrading to Grails 2.3.0 this stopped working and after a weekend of inactivity on the app I get this exception:

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 50,139,380 milliseconds ago.  The last packet sent successfully to the server was 50,139,380 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:3352)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1971)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619)
at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4997)
... 5 more
Caused by: java.net.SocketException: Write failed: Broken pipe
at jrockit.net.SocketNativeIO.socketWrite(SocketNativeIO.java:46)

有什么想法?

Any ideas ?

推荐答案

尝试将以下testOn属性添加到连接池配置:

Try adding the following "testOn" properties to your connection pool config:

  properties {
    ...
    testOnBorrow = true
    testWhileIdle = true
    testOnReturn = false
    validationQuery = "SELECT 1"
  }

值得以各种组合尝试这些标志。为了在您的环境中实现最佳性能,可能需要进行更改。

It's worth trying these flags in various combinations. Changes may be necessary for optimal performance in your environment.

这篇关于Grails 2.3.0和mysql连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆