在 ConnectionPooling 中移交给 WebApp 之前验证连接
我在 Spring 中使用 Oracle 数据源实现了连接池。目前我们面临着连接在一段时间后变得无效的问题。 (可能是 Oracle 一段时间后会删除这些空闲连接)。这是我的问题:
- Oracle 数据库是否可以配置为在特定时间段后自动删除空闲连接。因为我们预计这些连接会闲置一段时间;是否有任何此类配置;它可能正在发生。
在 Spring 的连接池属性中,我们没有“validateConnection”属性。据我所知,它会在将连接移交给网络应用程序之前验证连接?但这是否意味着如果连接通过 validateConnection 测试,那么它将始终正确连接到数据库。我问这个问题,因为我在这里读到以下问题: http://forum.springsource.org/showthread.php?t=69759
如果假设 validateConnection 没有完成整个 9 码的操作来确保连接有效,那么 DBCP 中是否还有其他选项,例如“testBeforBorrow”,它会运行测试查询以确保连接在将其移交给之前处于活动状态webapp?
如果您能为上面列出的一个或多个问题提供答案,我将不胜感激。
干杯
I have connection pooling implemented in spring using Oracle Data Source. Currently we are facing an issue where connections are becoming invalid after a period of time. (May be Oracle is dropping those idle connections after a while). Here are my questions:
- Can Oracle database be configured to drop idle connections automatically after a specific period of time. Since we expect those connections to lie idle for a while; if there is any such configuration; it may be happening.
In our connection pooling properties in spring we didn't have "validateConnection" property. I understand that it validates the connection before handing it over to web application? But does that mean that if a connection passes validateConnection test then it'll always connect to database correctly. I ask this, as I read following problem here:
http://forum.springsource.org/showthread.php?t=69759If suppose validateConnection doesn't do the whole 9 yards of ensuring that connection is valid, is there any other option like "testBeforBorrow" in DBCP , which runs a test query to ensure that connection is active before handing it over to webapp?
I'll be grateful if you could provide answers to one ore more queries listed above.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你没有说你正在使用什么应用程序服务器,或者你如何配置数据源,所以我无法给你具体的建议。
连接验证通常听起来是个好主意,但您必须小心谨慎。例如,我们曾经在 JBoss 应用程序服务器中使用它来验证池中的连接,然后再将它们交给应用程序。此 Oracle 专有机制使用 Oracle JDBC 驱动程序上的
ping()
方法,该方法检查连接是否仍处于活动状态。它工作得很好,但事实证明ping()
在服务器上执行“select 'x' from Dual
”,当它运行数十次时,这是一个非常昂贵的查询 因此,是,如果您有一个高流量服务器,请非常小心连接验证,它实际上会使您的数据库服务器崩溃。
道德 能够验证从池中借用的连接以及返回到池中的连接,并且您可以告诉它向数据库发送什么 SQL 来执行此验证,但是,如果您不使用 DBCP 进行连接池,那么这对您来说没有多大用处。
如果您使用应用程序服务器的数据源机制,那么您必须确定是否可以配置它来验证连接,这是特定于您的服务器的
。 :Spring 实际上并不涉及这里。Spring 只是使用您提供的
DataSource
,由DataSource
实现来执行连接验证。You don't say what application server you are using, or how you are configuring the datasource, so I can't give you specific advice.
Connection validation often sounds like a good idea, but you have to be careful with it. For example, we once used it in our JBoss app servers to validate connections in the pool before handing them to the application. This Oracle-proprietary mechanism used the
ping()
method on the Oracle JDBC driver, which checks that the connection is still alive. It worked fine, but it turns out thatping()
executes "select 'x' from dual
' on the server, which is a surprisingly expensive query when it's run dozens of times per second.So the moral is, if you have a high-traffic server, be very careful with connection validation, it can actually bring your database server to its knees.
As for DBCP, that has the ability to validate connections as their borrowed from the pool, as well as returned to the pool, and you can tell it what SQL to send to the database to perform this validation. However, if you're not using DBCP for your connection pooling, then that's not much use to you. C3PO does something similar.
If you're using an app server's data source mechanism, then you have to find out if you can configure that to validate connections, and that's specific to your server.
One last thing: Spring isn't actually involved here. Spring just uses the
DataSource
that you give it, it's up to theDataSource
implementation to perform connection validation.数据源“was”的配置如下:
已更改为:
Configuration of data source "was" as follows:
have changed it to: