Grails app第二天拒绝连接

时间:2014-08-07 15:58:18

标签: java mysql web-services grails

我使用grails编写了一个Web应用程序。它整天运行良好,但是当我醒来并在第二天检查它时,如果没有我重新加载,它将无法正常连接到数据库。 (MySQL的)。我觉得好像连接被拒绝了?

这是我的堆栈跟踪:

2014-07-28 13:28:07,103 [http-bio-8081-exec-93] ERROR StackTrace  - Full Stack Trace:
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.flush(Unknown Source)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3345)

这是我的数据源:

dataSource {

// Production
driverClassName = "com.mysql.jdbc.Driver"
username = "ROOT"
password = "PASS"
dbCreate = "update"
url = "jdbc:mysql://172.16.1.3/work_orders_v2"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"

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

}

我尝试了一些没有任何影响的事情。你能看到奇怪的东西吗? 谢谢。

2 个答案:

答案 0 :(得分:2)

使用以下适用于我的属性。

            properties {
            maxActive = -1
            minEvictableIdleTimeMillis=1800000
            timeBetweenEvictionRunsMillis=1800000
            numTestsPerEvictionRun=3
            testOnBorrow=true
            testWhileIdle=true
            testOnReturn=false
            validationQuery="SELECT 1"
            jdbcInterceptors="ConnectionState"
         }

答案 1 :(得分:2)

听起来您的池中的连接在闲置后被数据库服务器关闭。这是我期望发生的正常行为。

如果添加这些验证设置,则会在代码获取之前测试池中的连接。任何已关闭的连接都将从池中删除。

properties {
    maxActive = 50
    maxIdle = 25
    minIdle = 5
    initialSize = 5
    minEvictableIdleTimeMillis = 60000
    timeBetweenEvictionRunsMillis = 60000
    maxWait = 10000

    // Connection Validation Settings
    testOnBorrow=true
    testWhileIdle=true
    testOnReturn=true
    validationQuery="SELECT 1"
}