java 如何从正在运行的 JBoss 实例生成和分析线程转储?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/59787/
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-10-29 10:53:26  来源:igfitidea点击:

How do you generate and analyze a thread dump from a running JBoss instance?

javamultithreadingdump

提问by Teflon Ted

How do you generate and analyze a thread dump from a running JBoss instance?

如何从正在运行的 JBoss 实例生成和分析线程转储?

采纳答案by Matt Solnit

There is a JBoss-specific method that is slightly more user-friendly:

有一个 JBoss 特定的方法对用户更友好一些:

http://community.jboss.org/wiki/GenerateAThreadDumpWithTheJMXConsole

http://community.jboss.org/wiki/GenerateAThreadDumpWithTheJMXConsole

This is especially useful when you don't have direct access to the host machine (which "kill" would require).

当您无法直接访问主机(“杀死”需要)时,这尤其有用。

回答by Teflon Ted

http://java.sun.com/developer/technicalArticles/Programming/Stacktrace/

http://java.sun.com/developer/technicalArticles/Programming/Stacktrace/

...

...

"On UNIX platforms you can send a signal to a program by using the kill command. This is the quit signal, which is handled by the JVM. For example, on Solaris you can use the command kill -QUIT process_id, where process_id is the process number of your Java program.

“在 UNIX 平台上,您可以使用 kill 命令向程序发送信号。这是退出信号,由 JVM 处理。例如,在 Solaris 上,您可以使用 kill -QUIT process_id 命令,其中 process_id 是Java 程序的进程号。

Alternatively you can enter the key sequence <ctrl>\ in the window where the Java program was started. Sending this signal instructs a signal handler in the JVM, to recursively print out all the information on the threads and monitors inside the JVM."

或者,您可以在启动 Java 程序的窗口中输入键序列 <ctrl>\。发送此信号会指示 JVM 中的信号处理程序,以递归方式打印出有关 JVM 内线程和监视器的所有信息。”

...

...

"Determining the Thread States

"确定线程状态

You will see many different threads in many different states in a snapshot from a JVM stack trace. The key used is:

您将在来自 JVM 堆栈跟踪的快照中看到处于许多不同状态的许多不同线程。使用的密钥是:

R Running or runnable thread

R 正在运行或可运行的线程

S Suspended thread

S 悬线

CW Thread waiting on a condition variable

CW 线程等待条件变量

MW Thread waiting on a monitor lock

等待监视器锁的 MW 线程

MS Thread suspended waiting on a monitor lock"

MS 线程暂停等待监视器锁”

回答by Andrei

The stacktrace app found hereis also useful, especially on Windows machines when the java app is not started from the command line.

发现堆栈跟踪应用程序在这里也非常有用,尤其是在Windows机器上,当Java应用程序是不是在命令行启动。

回答by user98761

Thread.getAllStackTraces() (since Java 1.5)

Thread.getAllStackTraces()(从 Java 1.5 开始)

回答by Stephan

Two options:

两种选择:

OPTION 1Generate a thread dump using JMX Console

选项 1使用 JMX 控制台生成线程转储

In order to generate a thread dump:

为了生成线程转储:

  1. Open the JMXConsole (for example: http://localhost:8080)
  2. Navigate to jboss.system:type=ServerInfombean (hint:you can probably just CTRL-F and enter type=ServerInfo in the dialog box)
  3. Click on the link for the Server Info mbean.
  4. Navigate to the bottom where it says listThreadDump
  5. Click it and get your thread dump
  1. 打开JMXConsole(例如:http://localhost:8080
  2. 导航到jboss.system:type=ServerInfombean(提示:您可能只需按 CTRL-F 并在对话框中输入 type=ServerInfo)
  3. 单击服务器信息 mbean 的链接。
  4. 导航到它说的底部 listThreadDump
  5. 单击它并获取您的线程转储

Notes:

笔记:

If you are using Internet Explorer you should use File > Save Asto save the output instead of copying the data to a text editor. For some reason when you copy the text from Internet Explorer the line breaks are not copied and all of the output ends up on a single line.

如果您使用 Internet Explorer,您应该使用File > Save As保存输出而不是将数据复制到文本编辑器。出于某种原因,当您从 Internet Explorer 复制文本时,不会复制换行符,并且所有输出最终都在一行中。

OPTION 2Generate a Thread Dump using Twiddle

选项 2使用 Twiddle 生成线程转储

Alternatively you can use twiddle to execute the listThreadDump()method and pipe the returned HTML directly to file. Use this command line:

或者,您可以使用 twiddle 执行该listThreadDump()方法并将返回的 HTML 直接通过管道传输到文件。使用这个命令行:

<JBOSS_HOME>/bin/twiddle invoke "jboss.system:type=ServerInfo" listThreadDump > threads.html

回答by Vadzim

https://community.jboss.org/wiki/ThreadDumpJSPpage features standalone self-contained threaddump.war that can be used without JMX.

https://community.jboss.org/wiki/ThreadDumpJSP页面具有独立的自包含 threaddump.war,无需 JMX 即可使用。

回答by Vadzim

Sometimes JBoss locks so much that even jmx-concole doesn't respond. In such case use kill -3 on Linux and SendSignalon Windows.

有时 JBoss 锁定太多,甚至 jmx-concole 都没有响应。在这种情况下,在 Linux上使用 kill -3,在 Windows上使用SendSignal