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

后端 未结 7 2090
青春惊慌失措
青春惊慌失措 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条回答
  • 2020-12-08 08:39

    For grails 1.3.X, I had to add the following code to Bootstrap.groovy :

      def init = {servletContext ->
      def ctx=servletContext.getAttribute(ApplicationAttributes.APPLICATION_CONTEXT)
    
        //implement test on borrow
        def dataSource = ctx.dataSource
        dataSource.targetDataSource.setMinEvictableIdleTimeMillis(1000 * 60 * 30)
        dataSource.targetDataSource.setTimeBetweenEvictionRunsMillis(1000 * 60 * 30)
        dataSource.targetDataSource.setNumTestsPerEvictionRun(3)
        dataSource.targetDataSource.setTestOnBorrow(true)
        dataSource.targetDataSource.setTestWhileIdle(true)
        dataSource.targetDataSource.setTestOnReturn(false)
        dataSource.targetDataSource.setValidationQuery("SELECT 1")
    
      }
    

    I also had to import org.codehaus.groovy.grails.commons.ApplicationAttributes

    0 讨论(0)
提交回复
热议问题