0

I am searching for a way to kill a thread from a running JVM. I have the thread name, is there a way that I can stop the thread using external tools?

LeoTietz
  • 329
  • 4
  • 13
  • You can not kill/stop any JVM thread from outside of it. – Marcin Krasowski Aug 22 '14 at 20:59
  • Actually, htop shows a lot of threads from the process, but I am not sure if these are the actual thread. Also, the threads all look the same in htop, so I'm not sure which one to kill. – LeoTietz Aug 22 '14 at 21:01
  • But there is no syscall in kernel to kill a thread from outside of the owning process. – Marcin Krasowski Aug 22 '14 at 21:04
  • htop shows the actual threads. You can also see them with jstack, see [this answer](http://stackoverflow.com/a/4764205/2191722). But I think you'll just crash the jvm if you try to kill a thread. – Volune Aug 22 '14 at 21:10

3 Answers3

3

Unfortunately, there is no way to do this. The closest you can come is to kill the JVM process.

Alex Kleiman
  • 709
  • 5
  • 14
0

How about storing thread names and references in the hashmap and removing the entries when execution gets over? If you want to kill any specific thread, retrieve corresponding reference and stop it.

Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102
0

It seems to be possible if you write a debugger agent and connect to your app using JVMTI ...

user3970006
  • 151
  • 1