Spring DriverManagerDataSource vs apache BasicDataSource

对着背影说爱祢 提交于 2019-12-03 11:08:50

问题


What is the difference between Spring DriverManagerDataSource and apache BasicDataSource? Which of them is preferable and in which situations?

Thank you.


回答1:


As per the Spring documentation

This class is not an actual connection pool; it does not actually pool Connections. It just serves as simple replacement for a full-blown connection pool, implementing the same standard interface, but creating new Connections on every call.

If you need a "real" connection pool outside of a J2EE container, consider Apache's Jakarta Commons DBCP or C3P0. Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource are full connection pool beans, supporting the same basic properties as this class plus specific settings (such as minimal/maximal pool size etc).

Also read Controlling database connections

When using Spring's JDBC layer, you obtain a data source from JNDI or you configure your own with a connection pool implementation provided by a third party. Popular implementations are Apache Jakarta Commons DBCP and C3P0. Implementations in the Spring distribution are meant only for testing purposes and do not provide pooling.




回答2:


From Spring DriverManagerDataSource API:

This class is not an actual connection pool; it does not actually pool Connections. It just serves as simple replacement for a full-blown connection pool, implementing the same standard interface, but creating new Connections on every call.

In other words, it may be OK for tests but in real application use Apache DBCP



来源:https://stackoverflow.com/questions/17945137/spring-drivermanagerdatasource-vs-apache-basicdatasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!