当我执行 statement.execute()
时,有没有办法知道该语句是真的在执行还是在排队?或者,有没有办法执行 statement.status()
并知道它是否正在运行/排队?
这是为了检测花费很长时间的查询并阻止同一连接上的其他查询。
最佳答案
When I do statement.execute(), is there a way to know if the statement is really being executed or being queued?
不在 JDBC API 中。
Alternatively, is there a way to do statement.status() and know if it's running/queued ?
没有。
That's to detect queries taking a long time and blocking other queries on the same connection.
经典的 XY 问题。同一连接上不应任何其他并发查询。 JDBC 连接不是线程安全的。每个线程都应该有自己的连接。如果您使用线程池,每个方法都应该有自己的连接,差不多。
关于java - JDBC:我可以检测查询是否正在运行而不是排队吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34032882/