我似乎在我的 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)