Hibernate、C3P0、Mysql 连接池

发布于 2024-08-14 16:25:24 字数 253 浏览 9 评论 0原文

我最近从 Apache DBCP 连接池切换到 C3P0,并查看日志发现存在连接超时问题。我过去在使用 DBCP 和 Tomcat 时没有遇到过这种情况,所以我想知道这是配置问题还是驱动程序问题。

每当我在服务器空闲一段时间后加载页面时,我都会看到某些内容未发送(因为服务器无法获取连接或其他内容)。当我刷新页面时,所有内容都在那里。

既然我正在使用 MySQL,有人推荐使用 MySQL 连接池吗?您对 MySQL 连接池的体验如何?

瓦尔特

I recently switched from Apache DBCP connection pooling to C3P0 and have gone through my logs to see that there are connection timeout issues. I haven't had this in the past with DBCP and Tomcat, so I'm wondering if it is a configuration issue or driver issue.

Whenever I load a page after the server has been idle for a while, I'll see that some content is not sent (as the server cannot get a connection or something). When I refresh the page, all of the content is there.

Does anyone recommend using the MySQL connection pool since I'm using MySQL anyway? What are your experiences with the MySQL Connection Pool?

Walter

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

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

发布评论

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

评论(2

爱*していゐ 2024-08-21 16:25:24

如果您正在使用的数据库配置为在不活动一定时间后超时连接,则它们已经关闭,因此从池中借用它们时将无法使用。

如果您不能或不想重新配置数据库服务器,则可以配置 C3P0(以及大多数其他连接池),以便在从池中借用连接时使用测试查询来测试连接。您可以在C3P0 文档的相关部分中找到更多详细信息。

编辑:当然你是对的,也有可能是在 DBCP 池中配置了最大空闲时间,导致它们在超时之前被从池中删除。无论如何,使用测试查询或确保连接在超时之前从池中删除应该可以解决问题。

If the database you're working with is configured to timeout connections after a certain time of inactivity, they are already closed and thus unusable when they are borrowed from the pool.

If you cannot or do not want to reconfigure your database server, you can configure C3P0 (and most other connection pools) to test the connections with a test query when they are borrowed from the pool. You can find more detailed information in the relevant section of the C3P0 documentation.

Edit: Of course you're right, it's also possible that there was a maximum idle time configured in the DBCP pool, causing them to be removed from the pool before they would time out. Anyway, using either a test query or making sure the connections are removed from the pool before they time out should fix the problem.

奢望 2024-08-21 16:25:24

只需添加一个到另一个连接池的链接; BoneCP (http://jolbox.com);连接池比 C3P0 和 DBCP 都快。

与 C3P0 和 DBCP 一样,请确保配置空闲连接测试以避免出现您所描述的情况(可能 MySQL 的 wait_timeout 设置正在启动,通常设置为 8 小时)。

Just adding a link to another connection pool; BoneCP (http://jolbox.com); the connection pool that is faster than both C3P0 as well as DBCP.

Like C3P0 and DBCP, make sure you configure idle connection testing to avoid the scenario you described (probably MySQL's wait_timeout setting is kicking in, normally set to 8 hours).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文