适用于生产环境的最强大的数据源

发布于 2024-12-15 06:42:51 字数 145 浏览 3 评论 0原文

我使用 DriverManagerDataSource 进行本地开发。我目前正在使用 org.apache.commons.dbcp.BasicDataSource ,因为创建了太多连接。

有没有人对在连接池方面为客户端在生产中设置数据库的最佳方法有什么建议?

I was using DriverManagerDataSource for local development. I am currently using org.apache.commons.dbcp.BasicDataSource now because too many connections were being created.

Does anyone have suggestions on what the best way to go about setting up database in production for client is in terms of connection pools?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

向日葵 2024-12-22 06:42:51

看看BoneCP,速度相当快。

除了所有示例之外,还有常见问题解答,它可以为您提供有关连接池、角落的非常简洁和漂亮的概述案例,以及 BoneCP 如何处理它们。

Take a look a t BoneCP, it is quite fast.

Besides all the examples, there is FAQ that would give you a very concise and nice overview of connection pooling, corner cases, and how BoneCP handles them.

贵在坚持 2024-12-22 06:42:51

我通常倾向于使用 C3P0。对我来说总是很顺利。实际上并没有做过任何更深入的分析或比较,因为C3P0在性能和功能方面一直“足够好”。

I usually tend to go for C3P0. It's always worked out fine for me. Haven't actually done any deeper analysis or comparisons since C3P0 has always been "good enough" in terms of performance and functionality.

梦回梦里 2024-12-22 06:42:51

是的,我强烈建议为生产就绪的应用程序使用池数据源。

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">

DriverManagerDataSourceSingle-ConnectionDataSource 均提供连接池,无需设置池配置属性。

虽然 SingleConnectionDataSourceDriverManagerDataSource 很棒
对于小型应用程序和在开发中运行的应用程序,您应该认真考虑在生产应用程序中使用其中任何一个的影响。由于 SingleConnection-DataSource 只有一个数据库连接可供使用,因此它在多线程应用程序中无法正常工作。同时,即使 DriverManager-DataSource 能够支持多线程,它也会因每次请求连接时创建新连接而产生性能成本。由于这些限制,我强烈建议使用池数据源。

我展示了示例池数据源配置

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<propertyname="driverClassName"value="org.hsqldb.jdbcDriver"/>
<propertyname="url" value="jdbc:hsqldb:hsql://localhost/test"/>
<propertyname="username"value="sa"/>
<propertyname="password"value=""/>
<propertyname="initialSize"value="5"/>
<propertyname="maxActive"value="10"/>
</bean>

Yes,I strongly recommend using pooled data sources for Production ready applications.

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">

DriverManagerDataSource nor Single-ConnectionDataSource provides a connection pool, there are no pool configuration properties to set.

Although SingleConnectionDataSource and DriverManagerDataSource are great
for small applications and running in development, you should seriously consider the implications of using either in a production application. Because SingleConnection-DataSource has one and only one database connection to work with, it doesn’t work well in a multithreaded application. At the same time, even though DriverManager-DataSource is capable of supporting multiple threads, it incurs a performance cost for creating a new connection each time a connection is requested. Because of these limitations, I strongly recommend using pooled data sources.

I've shown sample Pooled DataSource configuration

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<propertyname="driverClassName"value="org.hsqldb.jdbcDriver"/>
<propertyname="url" value="jdbc:hsqldb:hsql://localhost/test"/>
<propertyname="username"value="sa"/>
<propertyname="password"value=""/>
<propertyname="initialSize"value="5"/>
<propertyname="maxActive"value="10"/>
</bean>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文