[dbcp] pooling configured/works fine. Few DBCP questions for experts.......

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[dbcp] pooling configured/works fine. Few DBCP questions for experts.......

Pramodh Peddi
I think I am done with getting the DB pooling work (of course, for my
prototype and I am hoping would work fie for the actual/production
application). Following are my questions/opinions to give myself a clear
understanding of the pooling:

* Database Pooling is done internally by tomcat and we do not
explicitly maintain any pool other than setting parameters in server.xml
right?
* When does tomcat create initial connections in the pool? During
server start up? If not when?
* What is the best/optimal DataSource (BasicDataSource?
PoolingDataSource?) to use to accomplish Connection pooling and also
PreparedStatement Pooling? And, should the 'factory' value in server.xml
be the corresponding value (BasicDataSourceFactory, etc)?
* Can we find out if we can programmatically know how many
Connections are there in the pool, how many are active, how many are
idle, etc? This is just to print these statistics (may be once an hour)
in the log file to ensure nothing is fishy with DB level.

 

 

Thanks in advance for the help.

 

- Pramodh.

Reply | Threaded
Open this post in threaded view
|

Re: [dbcp] pooling configured/works fine. Few DBCP questions for experts.......

Dirk Verbeeck
Answers inline.

Pramodh Peddi wrote:
> I think I am done with getting the DB pooling work (of course, for my
> prototype and I am hoping would work fie for the actual/production
> application). Following are my questions/opinions to give myself a clear
> understanding of the pooling:
>
> * Database Pooling is done internally by tomcat and we do not
> explicitly maintain any pool other than setting parameters in server.xml
> right?
Yes, tomcat will create a pool and bind it to JNDI . You can lookup and
use this pool. getconnection & conn.close()


> * When does tomcat create initial connections in the pool? During
> server start up? If not when?
When you first a connection from the pool.


> * What is the best/optimal DataSource (BasicDataSource?
> PoolingDataSource?) to use to accomplish Connection pooling and also
> PreparedStatement Pooling? And, should the 'factory' value in server.xml
> be the corresponding value (BasicDataSourceFactory, etc)?
The default tomcat datasource is a BasicDataSource created by
BasicDataSourceFactory. If you want to use getconnection(user, pass) to
connect to the database with different account then you can use a
PerUserPoolDataSource.
Examples for both are found on the wiki:
http://wiki.apache.org/jakarta-commons/DBCP


> * Can we find out if we can programmatically know how many
> Connections are there in the pool, how many are active, how many are
> idle, etc? This is just to print these statistics (may be once an hour)
> in the log file to ensure nothing is fishy with DB level.
>
>  
>
>  
>
> Thanks in advance for the help.
>
>  
>
> - Pramodh.
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [dbcp] pooling configured/works fine. Few DBCP questions for experts.......

Dirk Verbeeck
In reply to this post by Pramodh Peddi
That previous mail was send too fast, here is the answer to your last
question:

> * Can we find out if we can programmatically know how many
> Connections are there in the pool, how many are active, how many are
> idle, etc? This is just to print these statistics (may be once an hour)
> in the log file to ensure nothing is fishy with DB level.

Yes, if you cast the DataSource to the specific implementation then you
can print out usage statistics:
         BasicDataSource bds = (BasicDataSource) ds;
         System.out.println("NumActive: " + bds.getNumActive());
         System.out.println("NumIdle: " + bds.getNumIdle());

Regards
Dirk


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]