用于调试的工具在 Java 应用程序中挂起
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9833497/
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
Tool for debugging hangs in java application
提问by James T
I've got a java application that half the time just hangs, and the other half the JVM crashes. Is there a tool I can use to see what's going on that makes it hang and/or crash? I'm using CentOS 5.6
我有一个 Java 应用程序,一半时间挂起,另一半 JVM 崩溃。有没有我可以用来查看发生了什么使其挂起和/或崩溃的工具?我正在使用 CentOS 5.6
采纳答案by Jayan
There are two different cases.
有两种不同的情况。
Application crash:Was that an OOM? NPE? What was the exception? If there was jvm crash you will see hs_err_.log (http://java.sun.com/j2se/1.5/pdf/jdk50_ts_guide.pdf)
应用程序崩溃:这是一个 OOM 吗?NPE?有什么例外?如果有 jvm 崩溃,你会看到 hs_err_.log ( http://java.sun.com/j2se/1.5/pdf/jdk50_ts_guide.pdf)
Looking at the file you may see if your own JNI caused a crash or JVM bug.
查看该文件,您可能会看到您自己的 JNI 是否导致了崩溃或 JVM 错误。
Application Hang:I would start with visualvm or jstat (both are part of JDK). You can see current state of threads and check if there is any application error..
应用程序挂起:我会从 visualvm 或 jstat (两者都是 JDK 的一部分)开始。您可以查看线程的当前状态并检查是否有任何应用程序错误..
Other linux toolsthat could help to see inside process:
其他有助于查看内部进程的linux 工具:
- lsof: you can check if the process opened too many files
- strace: see current activity from system call point of view.
Oracle tools documentationprovides pretty neat listing. It also links Operating System Specific tools
Oracle 工具文档提供了非常简洁的列表。它还链接操作系统特定的工具
回答by ulmangt
For starters I would suggest JVisualVM. It comes with the JDK, so you should just need to type jvisualvm
into the command line to start it.
对于初学者,我建议使用JVisualVM。它随 JDK 一起提供,因此您只需要jvisualvm
在命令行中键入即可启动它。
Once it starts, you can connect to a running JVM, so you should be able to connect to your hung Java process and inspect the stack dump for all its running threads as well as the contents of the heap.
一旦它启动,您就可以连接到正在运行的 JVM,因此您应该能够连接到挂起的 Java 进程并检查所有正在运行的线程的堆栈转储以及堆的内容。
Other useful built-in tools include:
其他有用的内置工具包括:
jps
lists process ids of running java processes
jps
列出正在运行的 java 进程的进程 ID
jstack
prints a stack dump for each thread in the specified JVM process
jstack
为指定 JVM 进程中的每个线程打印堆栈转储
jmap
generates a heap dump for the specified JVM process (jvisualvm can also generate heap dumps)
jmap
为指定的JVM进程生成堆转储(jvisualvm也可以生成堆转储)
jhat
analyzes heap dumps generated with jmap or jvisualvm
jhat
分析使用 jmap 或 jvisualvm 生成的堆转储
Of couse, there are also more sophisticated profilers available. JProfileris quite highly regarded.
当然,还有更复杂的分析器可用。JProfiler备受推崇。
回答by aleroot
In these cases(hang, freeze, ...) you have to analyze an heap dump to try to figure out what's happening in your application , you can use JVisualVM to take the dump, or you can add the appropriate JVM parameter to dump the content of the heap in the case of a crash.
在这些情况下(挂起,冻结,...),您必须分析堆转储以尝试找出应用程序中发生的情况,您可以使用 JVisualVM 进行转储,或者您可以添加适当的 JVM 参数来转储崩溃时堆的内容。