porno porno rokettube
Results 1 to 2 of 2

Thread: Grails, Tomcat and a DataAccessResourceFailureException

  1. #1
    Administrator dave's Avatar
    Join Date
    Mar 2010
    Location
    West Yorkshire, UK - Valencia Spain
    Posts
    110

    Grails, Tomcat and a DataAccessResourceFailureException

    For those using MYSQL and have either updated to grails version 2 or starting with grails 2 which uses tomcat rather than Jetty as it's application server, and have run into this exception then this solution works perfectly well for me.


    The problem is related to JDBC and MySQL not freeing stale connections. I believe it happens when there hasnít been activity for over 8 hours, which is MySql's default wait time, which in my case happened everyday due to the overnight period.


    So what we should be doing is managing our own database connection pool. I use Tomcat 6 on my production servers so the following solution is specifically for tomcat 6.


    What we need to do is first change our application configuration so it sets up a database connection pool through tomcat. And secondly we need to tweak the configuration so that we validate the connection is present periodically and removed stale connections.
    The first thing then is to define the connection pool in <your application dir>/web-app/META-INF/context.xml
    A typical context.xml would be :


    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <Context path="/MyApplication">
     <Resource
       auth="Container"
       driverClassName="com.mysql.jdbc.Driver"
       maxActive="20"
       maxIdle="10"
       maxWait="-1"
       removeAbandoned="true"
       name="jdbc/myAppsPool"
       type="javax.sql.DataSource"
       url="jdbc:mysql://localhost:3306/Database_Name"
       username="user"
       password="password"
       validationQuery="SELECT '1'"
       removeAbandonedTimeout="60"
       logAbandoned="true"/>
    </Context>
    This alone will create the necessary database connection pool when you application is deployed.
    All thats left to do now is to change your datasource configuration to refer to the connection pool so in your DataSource.groovy file, locate the production section and alter it to refer to the new pool, e.g :


    Code:
    production {
      dataSource {
        pooled = false
        dbCreate = "update"
        jndiName = "java:comp/env/jdbc/myAppsPool"
      }
    }
    That should solve any of those DataAccessResourceFailureExceptions from now on.

  2. #2
    Junior Member
    Join Date
    Apr 2010
    Location
    Delaware USA
    Posts
    11
    Dave-

    We found a similar problem with stale connections in a commons dbcp datasource connection pool defined in our Grails app.
    We run Grails 1.1.1 with sybase ASE 12.5 on glassfish v2. For this dbcp datasource I'd found a tutorial on line which supports your solution as well
    http://sacharya.com/grails-dbcp-stale-connections/
    thanks
    Will

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Forum Design by Tucanoo Solutions Ltd Grails Development Specialists.