Quantcast

Number of connections in the pool using the datasource

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Number of connections in the pool using the datasource

José Cedeño
Hi,

I have connection pool set up in my grails application. I know that if I use "def dataSource" in a service class, I can use it to create a new groovy sql object and run sql queries by hand. Is it possible to use the same dataSource object or something else during run time to get the # of connections in the datasource pool?

Thanks,
José
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Number of connections in the pool using the datasource

sergiomichels
If is possible to access the BasicDataSource created by Grails, you can use the getNumActive method. I searched but not found this answer.

Regards,
Sérgio

On Mon, Jun 4, 2012 at 2:19 PM, José Cedeño <[hidden email]> wrote:
Hi,

I have connection pool set up in my grails application. I know that if I use "def dataSource" in a service class, I can use it to create a new groovy sql object and run sql queries by hand. Is it possible to use the same dataSource object or something else during run time to get the # of connections in the datasource pool?

Thanks,
José

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Number of connections in the pool using the datasource

José Cedeño
Sergio,

Thanks for the response. I found a different way of doing it, but it accomplishes the same:

Sql sql = new Sql(dataSource)
sql.dataSource.targetDataSource.connectionPool._pool.size()

Thanks,
José

-- 
José Cedeño
Sent with Sparrow

On Tuesday, June 5, 2012 at 9:16 AM, Sergio Michels wrote:

If is possible to access the BasicDataSource created by Grails, you can use the getNumActive method. I searched but not found this answer.

Regards,
Sérgio

On Mon, Jun 4, 2012 at 2:19 PM, José Cedeño <[hidden email]> wrote:
Hi,

I have connection pool set up in my grails application. I know that if I use "def dataSource" in a service class, I can use it to create a new groovy sql object and run sql queries by hand. Is it possible to use the same dataSource object or something else during run time to get the # of connections in the datasource pool?

Thanks,
José


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Number of connections in the pool using the datasource

burtbeckwith
You have to be careful with calls like these - they're very provider-specific. The DataSource interface only has a few methods so anything like these that access useful information will have different method names (or not even exist) with different pool implementations. If you decide later to switch to Tomcat Pool or C3P0 you will likely see errors on these calls.

Burt

José Cedeño wrote
Sergio,

Thanks for the response. I found a different way of doing it, but it accomplishes the same:

Sql sql = new Sql(dataSource)
sql.dataSource.targetDataSource.connectionPool._pool.size()

Thanks,
José


--  
José Cedeño
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Tuesday, June 5, 2012 at 9:16 AM, Sergio Michels wrote:

> If is possible to access the BasicDataSource created by Grails, you can use the getNumActive (http://commons.apache.org/dbcp/api-1.2.2/org/apache/commons/dbcp/BasicDataSource.html#getNumActive%28%29) method. I searched but not found this answer.
>  
> Regards,
> Sérgio
>  
> On Mon, Jun 4, 2012 at 2:19 PM, José Cedeño <[hidden email] (mailto:[hidden email])> wrote:
> > Hi,
> >  
> > I have connection pool set up in my grails application. I know that if I use "def dataSource" in a service class, I can use it to create a new groovy sql object and run sql queries by hand. Is it possible to use the same dataSource object or something else during run time to get the # of connections in the datasource pool?  
> >  
> > Thanks,
> > José
> >  
>  
>  
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Number of connections in the pool using the datasource

José Cedeño
Burt,

Thanks for the heads up. If I need to figure out the number of connections in the pool in the future, I will use more generic code like you specify. I just wanted to verify and test that the connection pooling was working with grails.

Thanks,
José

-- 
José Cedeño
Sent with Sparrow

On Tuesday, June 5, 2012 at 10:13 AM, burtbeckwith wrote:

You have to be careful with calls like these - they're very
provider-specific. The DataSource interface only has a few methods so
anything like these that access useful information will have different
method names (or not even exist) with different pool implementations. If you
decide later to switch to Tomcat Pool or C3P0 you will likely see errors on
these calls.

Burt


José Cedeño wrote

Sergio,

Thanks for the response. I found a different way of doing it, but it
accomplishes the same:

Sql sql = new Sql(dataSource)
sql.dataSource.targetDataSource.connectionPool._pool.size()

Thanks,
José


--
José Cedeño


On Tuesday, June 5, 2012 at 9:16 AM, Sergio Michels wrote:

If is possible to access the BasicDataSource created by Grails, you can
use the getNumActive
method. I searched but not found this answer.
Regards,
Sérgio
On Mon, Jun 4, 2012 at 2:19 PM, José Cedeño &lt;cedenoj@
([hidden email]@)&gt; wrote:
Hi,
I have connection pool set up in my grails application. I know that if
I use "def dataSource" in a service class, I can use it to create a new
groovy sql object and run sql queries by hand. Is it possible to use the
same dataSource object or something else during run time to get the # of
connections in the datasource pool?
Thanks,
José


--
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:


Loading...