简体   繁体   English

是否有Linux命令来打印正在运行的Java进程的当前堆栈

[英]Is there a Linux command to print the current stack of a running Java process

Situation: 情况:

I have a Java1.7 process running in CentOS6 with multiple threads. 我有一个在CentOS6中运行的具有多个线程的Java1.7进程。 The process currently halts (ie, stuck in some kind of loop or waiting function). 该进程当前停止 (即,停留在某种循环或等待功能中)。 Due to the complexity nature of the program, it is difficult to do a routine debug in, for instance, Eclipse (more explanation in the background section below). 由于程序的复杂性,很难在Eclipse中进行例行调试(在下面的背景技术部分中有更多说明)。 Therefore, I'd like to debug the code by tracing the current running stack. 因此,我想通过跟踪当前正在运行的堆栈来调试代码。

Question: 题:

Is there a Linux command that would allow me to print the stack to identify the thread/method that is currently running such that I can find which method is causing the halt? 是否有Linux命令可以让我打印堆栈以标识当前正在运行的线程/方法,以便我可以找到导致停止的方法?

Background: 背景:

The reasons for not being able to debug in Eclipse: 无法在Eclipse中进行调试的原因:

  1. It is a MapReduce program typically run on multiple computers. 它是一个MapReduce程序,通常在多台计算机上运行。
  2. Even if I use run on one computer, it still involves multiple threads running simultaneously. 即使我在一台计算机上使用运行,它仍然涉及多个线程同时运行。
  3. Most importantly, the "halting bug" occurs randomly (ie, not being able to reproduce). 最重要的是,“停止错误”是随机发生的(即无法复制)。 So my best shot is to identify the current running method that caused the bug. 因此,我最好的办法是确定导致该错误的当前运行方法。

PS My approach may be completely wrong, so feel free to correct me and point me in the right direction. PS:我的方法可能是完全错误的,所以请随时纠正我,并向正确的方向指出。

Thanks for your help. 谢谢你的帮助。

You can use JStack to get the current thread dump. 您可以使用JStack来获取当前的线程转储。 It should give you currently running threads and their stack traces. 它应该为您提供当前正在运行的线程及其堆栈跟踪。

It will even do more for you - should there be any deadlocks present it will tell you about them. 它甚至可以为您做更多-如果存在任何死锁,它将告诉您有关死锁的信息。

Apart from that you can also use JVisualVM to monitor your application in real time (you can check threads in real time there and take thread dumps from it). 除此之外,您还可以使用JVisualVM实时监视您的应用程序(您可以在那里实时检查线程并从中进行线程转储)。

From RedHat : RedHat

Following are methods for generating a Java thread dump on Unix: 以下是在Unix上生成Java线程转储的方法:

1) Note the process ID number of the Java process (eg using top, a grep on ps -axw, etc.) and send a QUIT signal to the process with the kill -QUIT or kill -3 command. 1)记录Java进程的进程ID号(例如,使用top,ps -axw上的grep等),并使用kill -QUIT或kill -3命令向该进程发送QUIT信号。 For example: 例如:

kill -3 JAVA_PID 杀死-3 JAVA_PID

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

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