how can i obtain a java thread dump in jre 180144?

There is a way if you are running with tools.jar available, that is running from a JDK instead of a stock JRE. However given that you don’t have the jcmd, jstack, jconsole tools available, this is unlikely.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;

// You need to add tools.jar to the classpath to get this
import com.sun.tools.attach.VirtualMachine;

public class Main {

    public static void main(String[] args) throws Exception {
        // Here you will need to use JNI or JNA to get the current process' PID
        // because the JRE version you are using doesn't have any other way.
        long pid = getCurrentPid(); // you need to create this method
        VirtualMachine vm = VirtualMachine.attach(""+pid);
            Method m = vm.getClass().getMethod("remoteDataDump", Object[].class);
            InputStream in = (InputStream) m.invoke(vm, new Object[] { new Object[0] } ); // awkward due to nested var-args
            try (BufferedReader buffer = new BufferedReader(new InputStreamReader(in))) {
                buffer.lines().forEach(System.out::println);
            }
    }
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top