MySQL Connection Timeout Issue - Grails Application on Tomcat using Hibernate and ORM

后端 未结 7 2127
青春惊慌失措
青春惊慌失措 2020-12-08 07:42

I have a small grails application running on Tomcat in Ubuntu on a VPS. I use MySql as my datastore and everything works fine unless I leave the application for more than ha

7条回答
  •  -上瘾入骨i
    2020-12-08 08:31

    In grails 1.3.X, you can modify the evictor values in the DataSource.groovy file to make sure pooled connections are used during idle. This will make sure the mysql server will not time out the connection.

    production {
      dataSource {
        pooled = true
        // Other database parameters..
        properties {
           maxActive = 50
           maxIdle = 25
           minIdle = 5
           initialSize = 5
           minEvictableIdleTimeMillis = 1800000
           timeBetweenEvictionRunsMillis = 1800000
           maxWait = 10000
        }
    }
    

    A quick way to verify this works is to modify the MySQL my.cnf configuration file [mysql] element and add wait_time parameter with a low value.

提交回复
热议问题