Using a JDK as the runtime image is simply a waste of resources, but it makes it a bit more difficult to get memory- and thread dumps out of the JVM at runtime.
Jattach to the rescue. Let’s imagine a situation where we have an image running your Java application using the JRE and you want to get a thread dump out of it.
First, we want to fetch the latest release of the Jattach binary.
Now that we have the binary, we need to make it executable.
chmod +x jattach
Not that we have an executable binary, we need the PID if the application. If you are running Java on the host, you can figure it out using ps -aux.
If you are running it in Docker, you’ll first need to figure out the image ID or -name. This can be done with docker ps. Next, use the image ID or -name to get the processes which are running in the container using docker top <image id or -name>.
That’s it, we’ve got all we need. To get a thread dump from the Java process, run the following command.
./jattach <pid> threaddump
There’s much more Jattach is able to do, check the readme page!