How to generate a Java Application thread dump from a Cloud Foundry container
search cancel

How to generate a Java Application thread dump from a Cloud Foundry container

book

Article ID: 297393

calendar_today

Updated On:

Products

VMware Tanzu Application Service for VMs

Issue/Introduction

This article explains how to generate a Java Application thread dump from a Cloud Foundry container.

Resolution

Method 1: `kill -3`

1. Capture the app log stream:

$ cf logs APP_NAME


2. SSH or login to the app container from another console window:

$ cf ssh APP_NAME


3. List the processes in the container and find the Java app process ID:

$ ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.0   1084     4 ?        S<s  Oct05   0:00 /tmp/garden-init
vcap          16  0.2  2.0 2202944 343068 ?      S<sl Oct05  11:41 /home/vcap/app/.java-buildpack/open_jdk_jre/bin/java -agentpath:/home/vcap/app/.java-buildpack/open_jdk_jre/bin/jvmkill-1.12.0_RELEASE=printH


4. Send SIGQUIT to the Java process.

$ kill -3 16


The thread dump is be available in app log stream.

   2021-07-15T16:18:56.44+0200 [APP/PROC/WEB/0] OUT 2021-07-15 14:18:56
   2021-07-15T16:18:56.44+0200 [APP/PROC/WEB/0] OUT Full thread dump OpenJDK 64-Bit Server VM (25.292-b10 mixed mode):
   2021-07-15T16:18:56.44+0200 [APP/PROC/WEB/0] OUT "RMI TCP Connection(idle)" #50 daemon prio=5 os_prio=0 tid=0x00005644e1a57800 nid=0x81 waiting on condition [0x00007f17a174d000]
   2021-07-15T16:18:56.44+0200 [APP/PROC/WEB/0] OUT    java.lang.Thread.State: TIMED_WAITING (parking)
   2021-07-15T16:18:56.44+0200 [APP/PROC/WEB/0] OUT 	at sun.misc.Unsafe.park(Native Method)
   2021-07-15T16:18:56.44+0200 [APP/PROC/WEB/0] OUT 	- parking to wait for  <0x00000000edd61aa0> (a java.util.concurrent.SynchronousQueue$TransferStack)
   2021-07-15T16:18:56.44+0200 [APP/PROC/WEB/0] OUT 	at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
   2021-07-15T16:18:56.44+0200 [APP/PROC/WEB/0] OUT 	at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460)
   2021-07-15T16:18:56.44+0200 [APP/PROC/WEB/0] OUT 	at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362)

 

Method 2: JMX + JvisualVM 

1. Set up JMX. For more information, refer to the article How to remotely Monitor Java Applications Deployed on PCF via JMX.

2. Start jvisualvm, right click Local, and click "Add JMX Connection...", input "localhost:" with the corresponding port.


3. Once the connection is ready under Local, click on it.

4. Click "Thread Dump" button under "Threads" tab, it takes a few seconds to generated the dump.
 

 

Method 3: Spring Actuators

For Spring apps with actuators enabled, thread dump is available at /dump endpoint in Spring Boot 1.x and /actuator/threaddump in Spring Boot 2.x. Refer to these Spring Boot references for details.