Unlocking lock owned by another thread java

前端 未结 5 948
借酒劲吻你
借酒劲吻你 2020-12-30 01:40

I have a LockManager that manages the locks of several threads. Sometimes the threads are bad boys, and I have to kill them and ask the LockManager to release all their lock

5条回答
  •  梦谈多话
    2020-12-30 02:16

    As stated in the comments, killing threads is not a good practice. Most frameworks do their best to interrupt threads in worker queues, but they will only have an effect if the executed code checks the interrupt flag, either by calling Thread.isInterrupted() or calling an interruptable IO or lock method.

    If you really need the concept of killing the execution of code, have a look at the Process class. You can create a Process by calling Runtime.exec() or using the ProcessBuilder. Calling Process.destroyForcibly() will forcibly terminate the running process.

提交回复
热议问题