2013-09-25 36 views
1

我似乎在我的Grails 2.2.4應用程序中隨機獲取以下警告。它看起來不像是造成任何問題,但它仍然有關。Grails maxRows/queryTimeout警告

我試圖在我的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") 
} 

既不嘗試阻止警告。 this的作者表示他已經成功地在tomcat config中設置了屬性,但我需要一個更通用的解決方案,它可以從命令行和其他服務器上運行。

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: "[email protected]: 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) 

回答

1

連接到我的MySQL數據庫超時後,我會看到確切的異常。我使用Grails docs中的建議更新了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 
    }