jdb可以杀死单个java线程吗?
理论上,JDB(java 调试器)允许杀死单个线程。实践中,可能吗?这里我将 jdb 连接到我的 JVM,它在端口 8000 处有一个 agentlib:
$ jdb -attach 8000
>
我列出了线程:
> threads
Group system:
(java.lang ...
[...]
我找到有问题的线程并尝试杀死它:
> kill 0x21bb new java.lang.Exception("die!")
killing thead: pool-766-thread-1
> com.sun.tools.example.debug.expr.ParseException: Unable to create java.lang.Exception instance
Expression must evaluate to an object
所以线程不能被杀死?
如何在 jdb 中创建一个新的异常,将其交给线程终止?
In theory, the JDB (java debugger) allows for a single thread to be killed. In practice, is it possible? Here I attach jdb to my JVM, which has an agentlib at port 8000:
$ jdb -attach 8000
>
I list the threads:
> threads
Group system:
(java.lang ...
[...]
I find the thread in question and try to kill it:
> kill 0x21bb new java.lang.Exception("die!")
killing thead: pool-766-thread-1
> com.sun.tools.example.debug.expr.ParseException: Unable to create java.lang.Exception instance
Expression must evaluate to an object
So threads cannot be killed?
How can one create a new Exception in the jdb, to give it to the thread to die?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下
但是以下答案可能确实回答了您的问题...
The following answer on SO does seems only to enforce your question.
But the following answer probably does answer your question...
您可能还运行 jconsole/jvisualvm。我遇到了同样的问题,但后来我关闭了 jconsole,jdb Kill 命令起作用了。
It is possible you have jconsole/jvisualvm also running. I had the same issue, but then I closed jconsole, the jdb kill command worked.
我想我知道你的问题是什么。您不能使用
jdb
杀死
线程,除非它们首先被挂起。但 JVM 中的一件奇怪的事情是你无法挂起正在睡眠的线程。如果它是“运行(在断点处)”,这实际上也意味着挂起,那么它可以被杀死:OTOH,如果你试图杀死一个正在睡眠的线程,这似乎是不可能的......
甚至切换到那个(睡眠)线程的自己的堆栈框架并不完全有帮助
另请注意 JDWP 特定线程 不能 就这样被杀了(通过 JDI,
jdb
也在下面使用),因为libjdwp
会在请求时出错。鉴于您的示例中涉及的线程名称pool-766-thread-1
,我不认为它是那些(JDWP)线程之一。I think I know what your problem was. You cannot
kill
threads withjdb
unless they are first suspended. But one of the strange things in JVM is that you cannot suspend a sleeping thread. If it's "running (at breakpoint)", which really also means suspended, then it can be killed:OTOH, if you're trying to kill a thread that's sleeping, that seems impossible...
Even switching to that (sleeping) thread's own stack frame doesn't exactly help
Also note that JDWP specific threads cannot be killed that way at all (via JDI, which
jdb
is also using underneath), aslibjdwp
will err on the request. Given the thread namepool-766-thread-1
involved in your example, I don't think it was one of those (JDWP) threads though.