Java 如何在 Eclipse 中强制线程转储?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/243298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 11:57:13  来源:igfitidea点击:

How to Force Thread Dump in Eclipse?

javaeclipsememory-leaksweblogic

提问by Paul Croarkin

I'm launching a Weblogic application inside Eclipse via the BEA Weblogic Server v9.2 runtime environment. If this were running straight from the command-line, I'd do a ctrl-BREAK to force a thread dump. Is there a way to do it in Eclipse?

我正在通过 BEA Weblogic Server v9.2 运行时环境在 Eclipse 中启动一个 Weblogic 应用程序。如果这是直接从命令行运行,我会按 ctrl-BREAK 来强制进行线程转储。有没有办法在 Eclipse 中做到这一点?

采纳答案by PhiLho

Indeed (thanks VonC to point to the SO thread), Dustin, in a comment to his message, points to jstack.

事实上(感谢 VonC 指向 SO 线程),Dustin 在对他的消息的评论中指向jstack

I have run a little Java application (with GUI) in Eclipse, I can see the related javaw.exe in Windows' process manager and its PID, 7088 (it is even simpler in Unix, of course).

我在 Eclipse 中运行了一个小 Java 应用程序(带有 GUI),我可以在 Windows 的进程管理器中看到相关的 javaw.exe 及其 PID,7088(当然,它在 Unix 中更简单)。

If I type at a command prompt jstack 7088, I have the wanted stack dump per thread.
Cool.

如果我在命令提示符下键入jstack 7088,则每个线程都有想要的堆栈转储。
凉爽的。

Would be better if we could do that directly from Eclipse, but that's already useful as is.

如果我们可以直接从 Eclipse 中做到这一点会更好,但这已经很有用了。

回答by VonC

Did you try to launch your eclipse with java.exe instead of javaw.exe (in your eclipse.ini) ?

您是否尝试使用 java.exe 而不是 javaw.exe (在您的eclipse.ini 中)启动您的日食?

That might give you the console you need, as described in this bugand in this message.

这可能会为您提供所需的控制台,如此错误此消息中所述

Other ideas (in term of java options) could be derived from this other SO question.

其他想法(在java选项方面)可以从this other SO question派生出来。

回答by Denis R.

You can do it when you are in debug mode: go to the debug view in the debug perspective, click on the process you have launched and click on pause, you will get a graphical stack of all your processes.

您可以在调试模式下执行此操作:转到调试透视图中的调试视图,单击已启动的进程并单击暂停,您将获得所有进程的图形堆栈。

Note : this also works when using remote debugging, you do not need to launch weblogic from eclipse, you can launch it on its own, open the debugging ports and create a "remote java application debug configuration" for it.

注意:这在使用远程调试时也有效,您不需要从 eclipse 启动 weblogic,您可以自行启动它,打开调试端口并为其创建“远程 java 应用程序调试配置”。

回答by Simon Lieschke

StackTraceis another option that you could try. From the features:

StackTrace是您可以尝试的另一个选项。从特点:

Thread dump for Java processes running as a Windowsservice (like Tomcat, for example), started with javaw.exe, applets running inside any browser or JVMs embedded inside another process. StackTrace works on Windows, Linux and Mac OS X.

作为Windows服务(例如 Tomcat)运行的 Java 进程的线程转储,从javaw.exe开始,在任何浏览器中运行的小程序或嵌入在另一个进程中的 JVM。StackTrace 适用于 Windows、Linux 和 Mac OS X。

回答by Martin Oberhuber

Eclipse Wiki: How to Report a Deadlocklists all possible options of creating a thread dump in Eclipse. Depending on the concrete situation, one or the other may work better -- my personal favorite on Windows is the Adaptj Stacktrace tool.

Eclipse Wiki:如何报告死锁列出了在 Eclipse 中创建线程转储的所有可能选项。根据具体情况,一种或另一种可能更有效——我个人在 Windows 上最喜欢的是 Adaptj Stacktrace 工具。

回答by Wiraj

You can connect through the JVisualVM and get a thread dump. Just right click on the application node from the Applications tree and select "Thread dump"

您可以通过 JVisualVM 连接并获取线程转储。只需右键单击应用程序树中的应用程序节点并选择“线程转储”

回答by Alper Akture

On linux at least you can do a ps -ef | grep javato get the PID and then do a kill -3 PIDand it will output it to the Eclipse console.

至少在 linux 上,您可以执行 aps -ef | grep java来获取 PID,然后执行 akill -3 PID并将其输出到 Eclipse 控制台。

回答by Peter Butkovic

if you prefer UI based solution visualvmmight be a good choice. (it's advantage is also that it's distributed with JDK)

如果您更喜欢基于 UI 的解决方案,visualvm可能是一个不错的选择。(它的优点还在于它与 JDK 一起分发)

To take the thread dump in visualvm:

在visualvm中进行线程转储:

  1. connect to process (remote or local) and
  2. go for Threads(tab) -> Thread Dump(button)
  1. 连接到进程(远程或本地)和
  2. Threads(标签)-> Thread Dump(按钮)