【发布时间】:2017-01-13 12:43:02
【问题描述】:
超时:池为空。无法在 10 秒内获取连接,无可用 [size:7;忙:0;空闲:0;最后等待:10000]
我的应用程序上线很长时间后出现上述错误。
以下是我的 GORM 数据库配置:
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)"
我该如何解决?
【问题讨论】:
-
你试过 reconnect=true 在 url 上吗? url = "jdbc:mysql://localhost:3306/test?autoReconnect=true" 很难说,因为你还没有定义 url....
-
我试过这个,但没有 validationQuery 属性。在这种情况下,连接很快就会关闭。但我还没有尝试使用validationQuery 自动重新连接
-
github.com/vahidhedayati/kchat/blob/master/grails-app/conf/… 我在生产环境中运行了这个配置,没有问题 validationQuery="SELECT 1" 必须设置它才能保持连接打开。
-
这意味着我不应该提供 maxActive 和 maxIdle 数。
-
但是没有这些数字,我们如何控制连接数。它可能会建立很多连接并减慢数据库。
标签: hibernate grails grails-orm