Best JDBC data source bean class

冷暖自知 提交于 2019-12-08 17:07:22

问题


I see that some people use org.apache.commons.dbcp.BasicDataSource while other configurations have com.mchange.v2.c3p0.ComboPooledDataSource.

Spring has its own: org.springframework.jdbc.datasource.DriverManagerDataSource

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....


回答1:


Spring has its own: org.springframework.jdbc.datasource.DriverManagerDataSource

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.

I have a JPA/Hibernate three tier application that needs connection pooling, but it looks like that all support this....

If you are using an application server, favor the connection pool of your application server.

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.

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.

See also

  • Connection pooling options with JDBC: DBCP vs C3P0


来源:https://stackoverflow.com/questions/2986038/best-jdbc-data-source-bean-class

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