Get the PID of Java
- ps -el | grep java
- top | grep java
jstack -F <your-pid> >dump.log
sudo jstack -F `pidof java` > /tmp/`hostname`_threaddump_`date +”%Y%m%d_%H%M”`.txt
Result:
hybris@aws-hybris5prd-ecom-app02:~$ jstack -F 31987 > dump_22_09_2015_3.log
Attaching to process ID 31987, please wait…
Debugger attached successfully.
Server compiler detected.
JVM version is 24.76-b04
Sometimes following error might occur:
Unable to open socket file: target process not responding or HotSpot VM not loaded The -F option can be used when the target process is not responding
Solution:
- jstck must be run as the same user as the java process which in my case is Jetty.
- sudo -u jetty jstack <your-pid> > dump.log
job done!!!