今天看到项目中的数据库连接池用的是org.springframework.jdbc.datasource.DriverManagerDataSource,对这个类并不是很熟悉,google后发现它并不是一个真正的数据库连接池。
Spring文档是这么描述它的:
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).
所以我们有三种方式来配置数据库连接池。
1,基于j2ee容器的jndi连接池
2,c3p0
3,dbcp