本文介绍了BasicDatasource和PoolingDatasource之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

org.apache.commons.dbcp BasicDatasource和PoolingDataSoure有什么区别?两者都支持连接池吗?何时使用它们?

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

推荐答案

BasicDataSource 是,作为说,一站式购物满足基本需求。它有所有必要的。它在内部创建了PoolableDataSource和ObjectPool。

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 使用提供的ObjectPool实现DataSource接口。 PoolingDatasource负责处理与连接有关的任何事情(转换,检查有效性,设置属性等),而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.

所以我应该使用BasicDataSource 。如果你需要一些特别的东西,可以使用PoolingDatasource和ObjectPool的另一个实现。但我认为这是一种罕见的情况。

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.

这篇关于BasicDatasource和PoolingDatasource之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 19:20