简体   繁体   English

如何调试JVM中的挂起线程?

[英]How do I debug hanging threads in the JVM?

I am running a durable Java program on a remote Ubuntu server, where I have root user rights. 我在具有root用户权限的远程Ubuntu服务器上运行持久的Java程序。 After some time, the usage on some CPU cores goes up to 100%. 一段时间后,某些CPU内核的使用率上升到100%。 The logs show nothing suspicious and the application still works, but with reduced throughput. 日志显示没有可疑之处,并且该应用程序仍然可以运行,但是吞吐量降低了。

How can I debug the JVM so that I can find out the cause of this, while it's still running? 我如何调试JVM,以便在它仍在运行时找出原因?

Connect to the process with jvisualvm 使用jvisualvm连接到进程

This tool will allow you to connect to the running process and view all of the threads and their state. 该工具将允许您连接到正在运行的进程,并查看所有线程及其状态。 This could show you which thread is the culprit merely by looking at which one is awake all the time. 仅通过查看哪个线程一直处于唤醒状态就可以向您显示哪个线程是罪魁祸首。 You can do a thread dump to see the stack trace for each thread and see what each thread is doing. 您可以执行线程转储以查看每个线程的堆栈跟踪,并查看每个线程在做什么。

It's a very powerful tool for just this kind of debugging. 对于这种调试,它是一个非常强大的工具。 It is distributed with the JDK only, so you will need more than just the JVM runtime installed to have access. 它仅与JDK一起分发,因此,您不仅需要安装JVM运行时才能进行访问。 Be sure you install the same version of the JDK that the JVM is running. 确保安装与JVM运行相同的JDK版本。

You will need to have your X display forwarded for this to work. 您需要转发X显示器才能正常工作。

One option is VisualVM , which is included in the JDK starting with Java 1.6. 一种选择是VisualVM ,它从Java 1.6开始包含在JDK中。 I have found it useful in some situations in the past. 我发现它在过去的某些情况下很有用。

You may connect to local applications or remote applications. 您可以连接到本地应用程序或远程应用程序。

To connect to a remote app, run jstatd on your remote server, and then run VisualVM locally and enter your server's IP address. 要连接到远程应用程序,请在远程服务器上运行jstatd ,然后在本地运行VisualVM并输入服务器的IP地址。 You should be provided with a list of running Java applications including the one you wish to explore. 应该为您提供一个正在运行的Java应用程序的列表,包括您希望浏览的Java应用程序。 If you have any trouble listing your application, good documentation is available at the VisualVM website. 如果您在列出应用程序时遇到麻烦,可以在VisualVM网站上找到良好的文档。

If you want to see the stack trace on linux just issue kill -SIGQUIT <java-program-pid> . 如果要查看Linux上的堆栈跟踪,只需发出kill -SIGQUIT <java-program-pid> That is one way to see where the the code is executing. 那是查看代码在哪里执行的一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM