Java JVM 线程转储位置

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

JVM thread dump location

javajvm

提问by user242591

When I issue a kill -3 <pid>command to my Java program, it generates the thread dump on the console. How do I redirect this to a file?

当我kill -3 <pid>向 Java 程序发出命令时,它会在控制台上生成线程转储。如何将其重定向到文件?

回答by ZoogieZork

Two options:

两种选择:

Run your Java application with stdout redirected

使用重定向的标准输出运行 Java 应用程序

java com.example.MyApp > out.txt

Use jstackinstead.

使用jstack来代替。

The jstackutility allows you to get a thread dump and send the output to the current console instead of the stdout of the Java application, allowing you to redirect it.

jstack工具可以让你获得一个线程转储和输出发送到当前控制台,而不是Java应用程序的标准输出,让您重定向它。

For example, if the PID of your Java application is 12345 (use the jpsutility to find it quickly):

例如,如果您的 Java 应用程序的 PID 为 12345(使用jps实用程序快速查找):

jstack 12345 > threads.txt

回答by Shane

If you want details of all threads and other JVM details, try jconsole.

如果您需要所有线程的详细信息和其他 JVM 详细信息,请尝试 jconsole。

回答by trashgod

I usually use the NetBeansprofiler, but jvisualvmis available from the command line.

我通常使用NetBeans分析器,但可以从命令行使用jvisualvm

回答by Arnab Biswas

Please append following JVM arguments to your application. Thread dump should be captured at dump.log.

请将以下 JVM 参数附加到您的应用程序。应该在 dump.log 中捕获线程转储。

-XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=dump.log

Please note it does not redirect, but enables JVM diagnostic logging. So, there could be possible over head as well.

请注意,它不会重定向,而是启用 JVM 诊断日志记录。因此,也可能存在开销。

However, if you can have JDK in the environment, using jstack or jcmd (jcmd is preferred with JDK 1.8), you can capture thread dump and redirect to a file.

但是,如果您可以在环境中使用 JDK,使用 jstack 或 jcmd(jcmd 是 JDK 1.8 的首选),您可以捕获线程转储并重定向到文件。