如何获取锁并在一段时间后强制释放它?爪哇
我有数据库和java线程死锁的问题,那么是否可以为java线程设置一段时间处于锁定状态,然后释放它,以防止所有系统挂起?通过这个技巧,我想释放数据库中的锁以使系统返回正常工作流程,无论某些查询会失败......
I have a problem with database and java threads deadlocks, so is it possible to set some time for java thread to be inside lock, and release it then, to prevent all system hang? By this trick I want to release lock in DB to return system to normal workflow and no matter that some query would fail...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
Statement.setQueryTimeout ()
。然而,在大多数情况下,这样做可能应该被视为一种黑客行为,而不是一个正确的解决方案。正如@lobster1234所说,找到并修复根本原因。
Try
Statement.setQueryTimeout()
.However, in most circumstances doing this should probably be considered a hack rather than a proper solution. As @lobster1234 has said, find and fix the root cause.
如果您的数据库支持(锁定)等待超时,请确保已配置它,或者使用 nowait 选项(如果可用)(这将立即报告锁定错误)
If your database supports a (lock) wait timeout, make sure it is configured, or use the nowait option if available (which will immediately report a lock error)