[JAVA] Take a thread dump in a JRE environment

There was a requirement to get a thread dump on a Windows server running an app on the JRE. Many things to think about

--You can get it normally with JDK, but jstack doesn't exist with JRE, so do you have to install JDK? -Is it possible to get a thread dump with a JDK installed with a different path for an application running on JRE? ――Do you have to run the app on the JDK? --Leave the JRE as it is and install the JDK additionally? You have to be careful about Path etc. ――JRE and JDK must match ver

I don't know various things, so I wonder what kind of error message I get, download an appropriate JDK, and try jstack on an appropriate Java application. I thought, but I don't have a suitable Java app, so I remembered that Eclipse works in Java, so I tried Eclipse (eclipse.exe).

moved

(I got a thread dump) ↑ Wrong use of heading (I wanted to make it big, but this is the only way to do it)

I don't know at all what ver and what Java runtime environment eclipse.exe is, but I understand this jstack works at all even if it is suitable It's okay if the path or ver is different between jstack and java to be acquired.

Next, we will verify it assuming acquisition in production

--On the in-house server where the app is running on JRE --Download and install the same version of JDK --Get thread dump for JRE app through path to JDK at command prompt

This is also OK

Let's go further and try to copy and execute only jstack.exe and the library

--Copy jstack.exe of JDK bin to JRE bin --Copy tools.jar of JDK lib to JRE lib --Get a thread dump to the application running on JRE with jstack copied to JRE bin --Error

java.util.ServiceConfigurationError: com.sun.tools.attach.spi.AttachProvider: Provider sun.tools.attach.WindowsAttachProvider could not be instantiated
1548: no providers installed

(I'm sorry, I wrote that I was able to do it in the first post, but when I tried again later, it was no good)

So, although it is necessary to install the JDK, I found that jstack can easily take a thread dump even with a JRE partner.

(Remarks)

――In the first place, you should use JDK from the beginning .. --This is the only command

jstack -l <PID>

--I got this error if I didn't place tools.jar ――When I searched for lib in the message displayed here, there was tools, so I put it and proceeded to the next (miscellaneous)

error:Main class sun.tools.jstack.JStack was not found or could not be loaded

The end

Recommended Posts

Take a thread dump in a JRE environment
Building a Lambda development environment in Eclipse
Creating a Servlet in the Liberty environment
Two ways to start a thread in Java + @
How to create a Java environment in just 3 seconds
[Note] Build a Python3 environment with Docker in EC2
Create a MySQL test environment (+ millions of test data) in 5 minutes
Install / run a standalone robot simulator in wsl2 / docker environment!
Resolve CreateProcess error = 206 when running Java in a Windows environment