Oracle 连接/查询超时

发布于 2024-08-04 14:19:28 字数 124 浏览 3 评论 0原文

是否可以为 Oracle 数据库查询指定连接/查询超时?在 Oracle 端还是在 Oracle 的 JDBC 驱动程序 (10.2.0.4) 中?那么,Java 客户端在 2 分钟后返回错误,而不是等到 Oracle 完成执行查询?

Is it possible to specify connection/query timeout for the Oracle database queries? Either on Oracle side or in Oracle's JDBC driver (10.2.0.4)? So, that Java client just got an error back after, let's say, 2 minutes instead of waiting until Oracle finishes executing the query?

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

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

发布评论

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

评论(4

情话已封尘 2024-08-11 14:19:28

如果您在事务上下文中执行查询,JTA 事务监视器的事务超时值将是查询超时的决定因素。此配置取决于一台应用程序服务器和另一台应用程序服务器。

在单个查询级别(在没有 JTA 事务监视器的情况下),setQueryTimeout 方法可用于设置 Statement/PreparedStatement/CallableStatement 对象的执行超时。

更新

setQueryTimeout 不可靠,尽管它可以工作(至少在 J2SE 客户端)。它通过 JDBC 驱动程序执行到 Oracle 数据库服务器的完整往返操作。然后,由数据库决定停止执行查询。不要依赖它来完成对时间要求严格的应用程序。

If you are executing the query in the context of a transaction, the transaction timeout value of the JTA transaction monitor will be the determinant to query timeout. The configuration for this depends from one application server to another.

At an individual query level (in the absence of a JTA transaction monitor), the setQueryTimeout method can be used to set the timeout on the execution of a Statement/PreparedStatement/CallableStatement object.

Update

setQueryTimeout is not to be relied on, although it works (atleast from a J2SE client). It works via the JDBC driver performing a full round-trip to the Oracle database server. Then, it is upto the database to halt execution of the query. Don't rely on it for time critical applications.

赠我空喜 2024-08-11 14:19:28

查看 Oracle 简介。这允许您在数据库级别指定多个限制。其中之一是每个查询的最大 CPU 时间。

如果您的查询定期运行时间超过 2 分钟,您可能需要首先对查询进行一些调整。

Have a look at Oracle profiles. This allows you to specify several limits at the database level. One of them is a maximum CPU time per query.

If you have queries running for more than 2 minutes on a regular basis you might want to do some tuning of your queries first.

红玫瑰 2024-08-11 14:19:28

根据 http://www.javamonamour.org/2012/09/oraclenetconnecttimeout.html< /a>

oracle.net.READ_TIMEOUT 对于 jdbc 版本 < 10.1.0.5 oracle.jdbc.ReadTimeout for jdbc versions >=10.1.0.5

因此,如果您使用 JDBC 驱动程序版本 10.1.0.5 或更高版本,则 oracle.jdbc.ReadTimeout 是正确的属性。

According to http://www.javamonamour.org/2012/09/oraclenetconnecttimeout.html

oracle.net.READ_TIMEOUT for jdbc versions < 10.1.0.5 oracle.jdbc.ReadTimeout for jdbc versions >=10.1.0.5

So if you are using a JDBC driver version 10.1.0.5 or higher, then oracle.jdbc.ReadTimeout is the correct property.

月依秋水 2024-08-11 14:19:28

设置 oracle.jdbc.ReadTimeout 有助于使 jdbc 调用超时。我已在生产 Spring Boot 应用程序中使用它,方法是指定数据源属性如下

spring.datasource.hikari.connection-timeout=1000
spring.datasource.hikari.dataSourceProperties=oracle.jdbc.ReadTimeout=2000

注意: 早些时候,此应用程序使用 tomcat 连接池,在设置上述属性后,发生了超时,但池是无法有效地处理关闭的连接对象。因此,我改用 hikariCP 并获得了更好的结果。我制作了一个 视频 模拟缓慢的 jdbc 调用,在使用 ReadTimeout 时将结果与 tomcat 和 hikari 连接池进行比较财产。

Setting oracle.jdbc.ReadTimeout helped to timeout the jdbc calls. I have used it in a production spring boot app by specifying datasource properties as below

spring.datasource.hikari.connection-timeout=1000
spring.datasource.hikari.dataSourceProperties=oracle.jdbc.ReadTimeout=2000

Note: Earlier this app was using tomcat connection pool and after setting the above properties for the same, timeouts were happening but the pool was not able to handle the closed connection objects efficiently. Therefore, I switched to hikariCP and got lot better results. I have made a video simulating the slow jdbc calls which compares the results with tomcat and hikari connection pools while using the ReadTimeout property.

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