简体   繁体   中英

How to acquire a lock and force release it after some time? 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...

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选项(如果有)(它将立即报告锁定错误)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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