Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between BasicDatasource and PoolingDatasource

What is the difference between org.apache.commons.dbcp BasicDatasource and PoolingDataSoure? Do both support pooling of connections? When to use each of them ?

like image 996
sam Avatar asked Sep 21 '11 07:09

sam


People also ask

What is BasicDataSource in Java?

BasicDataSource object, that is the basic implementation of javax. sql. DataSource that is configured via JavaBeans properties. In short, to create a simple BasicDataSource object you should: Create a BasicDataSource object and configure the database.

What is maxWaitMillis?

maxWaitMillis. indefinitely. The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or -1 to wait indefinitely.

What is Commons dbcp2?

The commons-dbcp2 artifact relies on code in the commons-pool2 artifact to provide the underlying object pool mechanisms. DBCP now comes in four different versions to support different versions of JDBC.


1 Answers

BasicDataSource is, as the javadoc says, a one-stop shopping for basic needs. It has all the necessary. It creates internally a PoolableDataSource and an ObjectPool.

PoolingDataSource implements the DataSource interface using a provided ObjectPool. PoolingDatasource take cares of whatever has to do with connections (casting, checking validity, setting properties, etc) and ObjectPool take cares of holding and counting this whatever-type-it-is object.

So I should use BasicDataSource. If you need something special maybe can use PoolingDatasource with another implementation of ObjectPool. But I think it would be a rare case.

like image 161
helios Avatar answered Sep 20 '22 06:09

helios