1

我似乎在我的 Grails 2.2.4 应用程序中随机收到以下警告。看起来它不会引起任何问题,但它仍然令人担忧。

我试图通过修改DataSource.groovy文件中的数据源属性来防止出现此警告:

dataSource {
    pooled = true
    properties {
        maxWait = 10000 // 10 seconds
        minEvictableIdleTimeMillis = 1000 * 60 * 30 // 30 minutes
        numTestsPerEvictionRun = 3
        testOnBorrow = true
        testOnReturn = false
        testWhileIdle = false
        timeBetweenEvictionRunsMillis = 1000 * 60 * 30 // 30 minutes
        validationQuery = "SELECT 1"
    }
}

当这不起作用时,我尝试在我的BootStrap.groovy文件中设置属性:

def init = { servletContext ->
    def ctx = Holders.getApplicationContext()
    def dataSource = ctx.dataSourceUnproxied

    println "configuring database connection pool"

    dataSource.setMinEvictableIdleTimeMillis(1000 * 60 * 30)
    dataSource.setTimeBetweenEvictionRunsMillis(1000 * 60 * 30)
    dataSource.setNumTestsPerEvictionRun(3)
    dataSource.setTestOnBorrow(true)
    dataSource.setTestWhileIdle(false)
    dataSource.setTestOnReturn(false)
    dataSource.setValidationQuery("SELECT 1")
}

两种尝试都不会阻止警告。这篇文章的作者说他已经成功地直接在 tomcat 配置中设置了属性,但是我需要一个更通用的解决方案,可以在命令行和其他服务器中工作。

2013-09-25 15:07:51,027 [http-bio-8080-exec-9] WARN  jdbc.AbstractBatcher  - exception clearing maxRows/queryTimeout
java.sql.SQLException: org.apache.commons.dbcp.DelegatingPreparedStatement with address: "com.mysql.jdbc.JDBC4PreparedStatement@13ed0db0: EXCEPTION: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after statement closed." is closed.
    at org.apache.commons.dbcp.DelegatingStatement.checkOpen(DelegatingStatement.java:137)
    at org.apache.commons.dbcp.DelegatingStatement.getMaxRows(DelegatingStatement.java:237)
    at ace_2.DefsUploadController.upload(DefsUploadController.groovy:16)
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
4

1 回答 1

1

在连接到我的 MySQL 数据库超时后,我也会看到确切的异常。我使用Grails 文档中的建议作为指导更新了 DataSource 配置,但我还没有看到关闭连接的任何异常。

这是我当前的设置:

    properties {
        initialSize=5
        maxActive=50
        minIdle=5
        maxIdle=25
        maxWait = 10000
        maxAge = 10 * 60000
        timeBetweenEvictionRunsMillis = 5000
        minEvictableIdleTimeMillis = 60000
        validationQuery = "SELECT 1"
        validationQueryTimeout = 3
        validationInterval = 15000
        testOnBorrow = true
        testWhileIdle = true
        testOnReturn = false
        jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
        defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
    }
于 2014-05-17T04:21:26.490 回答