My java process is running inside the container. Of course I can see that process on host machine and see its pid as well. If jdk is not installed on the cluster but on the host, can I run jstack from the host against the java process in the docker container, using this pid. By the way, I tried it and ran into following error
Attaching to process ID 66367, please wait...
Error attaching to process: Doesn't appear to be a HotSpot VM (could not find symbol "gHotSpotVMTypes" in remote process)
sun.jvm.hotspot.debugger.DebuggerException: Doesn't appear to be a HotSpot VM (could not find symbol "gHotSpotVMTypes" in remote process)
at sun.jvm.hotspot.HotSpotAgent.setupVM(HotSpotAgent.java:411)
at sun.jvm.hotspot.HotSpotAgent.go(HotSpotAgent.java:305)
at sun.jvm.hotspot.HotSpotAgent.attach(HotSpotAgent.java:140)
at sun.jvm.hotspot.tools.Tool.start(Tool.java:185)
at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
at sun.jvm.hotspot.tools.JStack.main(JStack.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.tools.jstack.JStack.runJStackTool(JStack.java:140)
at sun.tools.jstack.JStack.main(JStack.java:106)
Ctrl + Break (Windows) In Windows operating systems, we can capture a thread dump using the CTRL and Break key combination. To take a thread dump, navigate to the console used to launch the Java application, and press the CTRL and Break keys together.
jstack. file-path: is the file path where thread dump will be written in to. As per the example thread dump of the process would be generated in /opt/tmp/threadDump.
Execute the following to get the Tomcat threads dump: root@localhost:~# sudo -u $TOMCAT_USER $JAVA_HOME/bin/jstack -J-d64 -l $(ps aux | grep '[c]atalina' | awk '{print $2}') > ~/threads. log. Open the threads dump with IBM Thread & Dump Monitor Analyzer.
The jstack version you are using needs to come from the exactly same JVM version your software is running.
Running jstack
within the application container will work.
You can also run jstack
in remote debugging after activating the remote debugging server / jmx on your software.
Also, if your container doesn't have jstack, you can probably run a container built with the same jvm but ships jstack, in the same pid namespace of your jvm container by running:
docker run --pid=container:your_app your_jstack_images jstack $in_your_app_container_jvms_pid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With