问题描述
我看到有些人使用 org.apache.commons.dbcp.BasicDataSource ,而其他配置有 com.mchange.v2.c3p0.ComboPooledDataSource 。
I see that some people use org.apache.commons.dbcp.BasicDataSource while other configurations have com.mchange.v2.c3p0.ComboPooledDataSource.
Spring有自己的: org.springframework.jdbc.datasource.DriverManagerDataSource
Spring has its own: org.springframework.jdbc.datasource.DriverManagerDataSource
可能还有更多。但哪一个最好?我有一个JPA / Hibernate三层应用程序需要连接池,但它看起来像都支持这个....
There are probably even more. But which one is best? I have a JPA/Hibernate three tier application that needs connection pooling, but it looks like that all support this....
推荐答案
类实现接口,但不一个连接池,类,并且可以在开发期间使用,而不是真正的池(但它会在每次调用时创建一个新的连接)。我建议阅读其。
The class org.springframework.jdbc.datasource.DriverManagerDataSource implements the DataSource interface but is NOT a connection pool, it's just a convenient class that and can be used during development instead of a real pool (but it creates a new connection on every call). I'd suggest to read its javadoc.
如果您使用应用程序服务器,则优先使用应用程序服务器的连接池。
If you are using an application server, favor the connection pool of your application server.
如果你不是,那么DBCP,C3P0是最常见的解决方案。 会使用C3P0(这实际上是与Hibernate现在而不是DBCP绑定),我在高负载下面临一些死锁问题,而不是C3P0,所以我倾向于喜欢C3P0。
If you are not, then DBCP, C3P0 are the most common solutions. I would use C3P0 (which is actually bundled with Hibernate now instead of DBCP), I faced some deadlock issues with DBPC under high load, not with C3P0 so I tend to prefer C3P0.
可能值得注意的是,DBCP最近在非常长时间的不活动(而C3P0处于非活动状态)后已复活,因此可能会变得更好。
It may be worth noting that DBCP has been resurrected very recently after a very long period of inactivity (while C3P0 is inactive) and might thus get better.
其他玩家包括和(最近的新竞争对手)。后来看起来很有趣,但我没有任何实际经验。
Other players include Proxool and BoneCP (a recent new competitor). The later looks interesting but I don't have any practical experience with it.
在任何情况下,您都应该在进行生产前执行健壮性测试。
In any case, you should typically run robustness tests before going to production.
- Connection pooling options with JDBC: DBCP vs C3P0
这篇关于最好的JDBC数据源bean类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!