简体   繁体   中英

Command to Interrupt a hung thread running in a java process without code changes

I've a java process running and unfortunately one thread inside the process is hung .

I found the Thread id which was hung using jstack , however I was unable to find any references on how to interrupt this thread using the id?

Is it possible to Interrupt/Stop a thread from console (or basically outside the process) by using the processId and ThreadId?

Any suggestions on how to tackle this?

PS : I don't want to kill the process as its just one thread which is hung. Also, neither do I want to make code changes to Stop/Interrupt the thread. I just want to kill it, so all its resources can be released.

There's no baked-in way to kill a thread within the JVM, at least not a deliberately implemented one.

Having said that, if you have started your JVM with the appropriate parameters, so that you can start a remote JMX session to it, you can actually suspend the thread and inject a RuntimeException into it, which will almost surely terminate it (unless you are doing something gnarly with RuntimeException s in it).

PS You would never start your JVM in production allowing rogue JMX connections though, and if you're not in production, I'd guess that the above approach is not of much help to you.

You should be able to send a SIGINT to the process, this should be received by all threads. (That is the catch (InterruptedException ex) ...)

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