user2722142
user2722142

Reputation:

Connection Pooling in Grails 2.2.x?

I could not find how connection pooling is activated in Grails.

In my DataSource.groovy I have the following:

        url = "jdbc:mysql://localhost/myapp?useUnicode=yes&characterEncoding=UTF-8"
        username = "root"
        password = ""
        dialect = org.hibernate.dialect.MySQL5InnoDBDialect
        pooled = true
        properties {
            maxActive = -1
            minEvictableIdleTimeMillis=1800000
            timeBetweenEvictionRunsMillis=1800000
            numTestsPerEvictionRun=3
            testOnBorrow=true
            testWhileIdle=true
            testOnReturn=true
            validationQuery = "select 1"

        }

Is there something else I have to do to activate connection pooling than setting pooled = true?

Upvotes: 1

Views: 2561

Answers (2)

pm_labs
pm_labs

Reputation: 1145

Below is a sample from Grails DataSource documentation page:

dataSource {
pooled = true
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/my_database"
driverClassName = "com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
username = "username"
password = "password"
properties {
   jmxEnabled = true
   initialSize = 5
   maxActive = 50
   minIdle = 5
   maxIdle = 25
   maxWait = 10000
   maxAge = 10 * 60000
   timeBetweenEvictionRunsMillis = 5000
   minEvictableIdleTimeMillis = 60000
   validationQuery = "SELECT 1"
   validationQueryTimeout = 3
   validationInterval = 15000
   testOnBorrow = true
   testWhileIdle = true
   testOnReturn = false
   jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
   defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}}

In addition to setting pooled to true, you can also tweak settings on how many connections are initialized up front (initialSize) and the maximum number of connections you would want to maintain when the load gets higher (maxActive).

Upvotes: 0

Burt Beckwith
Burt Beckwith

Reputation: 75671

No, the pooled attribute configures pooling. If it's set to false then you will create a new connection each time, and this can take hundreds of milliseconds, so it's not advised.

You would set pooled = false when using JNDI however, since the JNDI datasource does its own pooling, so there's no need to pool twice.

Upvotes: 2

Related Questions