gpt4 book ai didi

mysql - Grails 应用程序(Hibernate、Tomcat、mysql)中空闲时间后没有数据库连接

转载 作者:行者123 更新时间:2023-11-29 22:24:46 25 4
gpt4 key购买 nike

我有在 Tomcat 上运行的 Grails 应用程序。部署应用程序后一切正常。几个小时不活动后,它将不再工作。

我的数据源.groovy:

production {
dataSource {
pooled = true
dbCreate = "update"
url = "jdbc:mysql://localhost/myapp?autoReconnect=true"
driverClassName = "com.mysql.jdbc.Driver"
username = "user"
password = "password"
properties {
maxActive = 100
maxIdle = 25
minIdle = 5
maxAge = 10 * 60000
initialSize = 5
minEvictableIdleTimeMillis = 10000
timeBetweenEvictionRunsMillis = 6000
maxWait = 300
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
validationInterval = 15000
}
}
}

catalina.out:

May 20, 2015 2:03:42 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 44068 ms
2015-05-21 02:17:23,048 [http-bio-8080-exec-1] ERROR spi.SqlExceptionHelper - Communications link failure

The last packet successfully received from the server was 31,419,946 milliseconds ago. The last packet sent successfully to the server was 169 milliseconds ago.
2015-05-21 02:17:23,113 [http-bio-8080-exec-1] ERROR support.TransactionTemplate - Application exception overridden by rollback exception
org.springframework.dao.RecoverableDataAccessException: Hibernate operation: could not prepare statement; SQL [select this_.id as id1_3_0_, this_.version as version2_3_0_, this_.account_expired as account_3_3_0_, this_.account_locked as account_4_3_0_, this_.birthday as birthday5_3_0_, this_.departure as departur6_3_0_, this_.email as email7_3_0_, this_.enabled as enabled8_3_0_, this_.first_name as first_na9_3_0_, this_.joining as joining10_3_0_, this_.last_name as last_na11_3_0_, this_.`password` as passwor12_3_0_, this_.password_expired as passwor13_3_0_, this_.role_id as role_id14_3_0_, this_.username as usernam15_3_0_ from user this_ where (this_.username=?) limit ?]; Communications link failure

The last packet successfully received from the server was 31,419,946 milliseconds ago. The last packet sent successfully to the server was 169 milliseconds ago.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 31,419,946 milliseconds ago. The last packet sent successfully to the server was 169 milliseconds ago.
at org.grails.datastore.gorm.GormStaticApi.findWhere(GormStaticApi.groovy:622)
at grails.plugin.springsecurity.userdetails.GormUserDetailsService$_loadUserByUsername_closure1.doCall(GormUserDetailsService.groovy:64)
at org.grails.datastore.gorm.GormStaticApi.withTransaction(GormStaticApi.groovy:815)
at org.grails.datastore.gorm.GormStaticApi.withTransaction(GormStaticApi.groovy:715)
at grails.plugin.springsecurity.userdetails.GormUserDetailsService.loadUserByUsername(GormUserDetailsService.groovy:63)
at grails.plugin.springsecurity.userdetails.GormUserDetailsService.loadUserByUsername(GormUserDetailsService.groovy:81)
at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.attemptAuthentication(RequestHolderAuthenticationFilter.java:76)
at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:49)
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:82)
at grails.plugin.springsecurity.rest.RestLogoutFilter.doFilter(RestLogoutFilter.groovy:80)
at com.brandseye.cors.CorsFilter.doFilter(CorsFilter.java:82)
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:745)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 31,419,946 milliseconds ago. The last packet sent successfully to the server was 169 milliseconds ago.
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1129)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3720)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4160)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2828)
at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:5372)
... 14 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3166)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3620)
... 20 more
2015-05-21 02:18:05,539 [http-bio-8080-exec-6] ERROR spi.SqlExceptionHelper - Communications link failure

最佳答案

我们也遇到了类似的问题 - 我们应用程序的数据源 block 现在看起来像这样:

    dataSource {
dialect = org.hibernate.dialect.MySql5InnoDbDialect
driverClassName = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost:3306/myapp?autoreconnect=true"
username = "[username]"
password = "[password]"
pooled = true
properties {
validationQuery = "SELECT 1"
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
maxActive = 50
maxIdle = 25
minIdle = 5
initialSize = 5
minEvictableIdleTimeMillis = 1800000
timeBetweenEvictionRunsMillis = 1800000
maxWait = 10000
}
}

关于mysql - Grails 应用程序(Hibernate、Tomcat、mysql)中空闲时间后没有数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30370178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com