Hibernate Grails Gorm超时:池为空。无法获取连接
超时:池为空。无法在10秒内获取连接,无可用连接[size:7;busy:0;idle:0;lastwait:10000] 上面的错误是在我的应用程序运行了很长时间之后出现的 下面是我的GORM db配置:Hibernate Grails Gorm超时:池为空。无法获取连接,hibernate,grails,gorm,Hibernate,Grails,Gorm,超时:池为空。无法在10秒内获取连接,无可用连接[size:7;busy:0;idle:0;lastwait:10000] 上面的错误是在我的应用程序运行了很长时间之后出现的 下面是我的GORM db配置: propertyShortSlave: pooled: true jmxExport: true driverClassName: com.mysql.jdbc.Driver url: url username: uuuuuu password
propertyShortSlave:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
url: url
username: uuuuuu
password: pppppp
dbCreate: validate
readOnly: true
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
properties:
initialSize: 5
maxActive: 7
minIdle: 5
validationQuery: SELECT 1
maxIdle: 7
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: "ConnectionState;StatementCache(max=200)"
如何修复它?尝试使用以下方法:
dataSource {
....
url = "jdbc:mysql://localhost:3306/databaseName?autoReconnect=true&useUnicode=true&CharSet=UTF-8&characterEncoding=UTF-8"
....
properties {
....
validationQuery = "SELECT 1"
....
}
}
您是否已尝试在url上重新连接=true?url=“jdbc:mysql://localhost:3306/test?autoReconnect=true“很难说,因为您还没有定义url…我尝试过这个,但没有validationQuery属性。在这种情况下,连接很快就会关闭。但我没有尝试使用validationQuery自动恢复连接我在生产环境中运行了此配置,但没有问题validationQuery=“SELECT 1”必须设置为使连接保持打开状态。这意味着我不应提供maxActive和maxIdle号码。但如果没有这些号码,我们如何控制连接的数量。它可能会产生大量连接并降低数据库的速度。您是以JSON格式发布的,实际上,它是以YAML格式发布的。但是这个想法是正确的,这是Grails在2.x版本中使用的groovy闭包。YAML在Grails 3.xCorrect之后介绍,我只是给问题的作者做个笔记,因为不同的格式可能会让新手感到困惑。@Jeeveshpandey,我还没有尝试过这个结果,因为现在我的连接工作正常,但当问题再次出现时,我将应用此解决方案。目前,我只是将maxActive连接数增加到20。让我们看看它是如何工作的。