简体   繁体   English

Oracle的JDBC查询超时是如何实现的?

[英]How is Oracle's JDBC query timeout implemented?

I was curious as to how the Oralce JDBC thin client implement query timeout. 我很好奇Oralce JDBC瘦客户端如何实现查询超时。 This can be set by calling java.sql.Statement's setQueryTimeout(int seconds) method. 这可以通过调用java.sql.Statement的setQueryTimeout(int seconds)方法来设置。

Is this implemented in the driver itself on the client side? 这是在客户端的驱动程序本身实现的吗? Is a new thread spawned and joined? 是一个新的线程产生并加入? Or does the JDBC driver simply send a parameter to Oracle, and then it enforces the timeout? 或者JDBC驱动程序是否只是向Oracle发送参数,然后它会强制执行超时?

After the timeout is reached, which resources on the client and database are released, and which hang around? 达到超时后,客户端和数据库上的哪些资源被释放,哪些存在? Does Oracle continue to run the query even though the client abandoned it or is it terminated? 即使客户端放弃了查询还是终止,Oracle是否继续运行查询? Is there still a cursor object on the client side? 客户端是否还有游标对象?

Thank you 谢谢

According to Oracle JDBC FAQ 根据Oracle JDBC FAQ

Statement timeout thread. 语句超时线程。 This thread is created if you execute any statement with a timeout. 如果执行任何超时语句,则会创建此线程。 Only one thread is created no matter how many statements or connections. 无论有多少语句或连接,都只创建一个线程。 This thread lasts the lifetime of the VM. 该线程持续VM的生命周期。

Tanel Poder wrote an article on how a Cancel works through the OCI (Oracle Call Interface). Tanel Poder写了一篇关于Cancel如何通过OCI(Oracle调用接口)工作的文章。 I guess something similar is done for JDBC. 我想对JDBC做了类似的事情。 If you are using the thick driver, through OCI, you could try tracing the session (through settings sqlnet.ora) and see what gets recorded. 如果您使用厚驱动程序,通过OCI,您可以尝试跟踪会话(通过设置sqlnet.ora)并查看记录的内容。

When a query actually timesout when using the setTimeOut method, a SQL exception with the Oracle error code ORA-01013 - user requested cancel of current operation is thrown from the oracle server. 当查询在使用setTimeOut方法时实际超时时,将从oracle服务器抛出带有Oracle错误代码ORA-01013 - user requested cancel of current operation的SQL异常ORA-01013 - user requested cancel of current operation

This would mean that the operation has been cancelled gracefully (as far as oracle is concerned/as much oracle can) - because it is oracle sending this message. 这意味着操作已被优雅地取消(就oracle而言/ oracle可以) - 因为它是oracle发送此消息。

I do know that the query does not continue on the server side when the timeout is reached. 我知道当达到超时时,查询不会在服务器端继续。 There is some intention/signal option sent to the server either before or after the timeout is reached to indicate it the server should stop. 在达到超时之前或之后,有一些意图/信号选项发送到服务器,以指示服务器应该停止。 I have verified this by looking on the server in various V$ tables to see if the query is running. 我已经通过查看各种V $表中的服务器来验证这一点,以查看查询是否正在运行。 (V$SESSION, V$SQL, etc) (V $ SESSION,V $ SQL等)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM