I'd like to kill threads that are stuck in deadlock state. First, we can detect thread ids in deadlock state using the findDeadlockedThreads()
method of the ThreadMXBean
class in java.lang.management
.
Then, I'd like to kill the threads by thread ids, and thus I have two related questions:
(1) How to get the control of a thread by thread id?
(2) How to kill a blocked thread? I think that invokting interrupt() method will give an exception to the thread and will kill the thread.