Skip to content

Instantly share code, notes, and snippets.

@bjorndarri
Created January 22, 2019 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjorndarri/843afdd5400abe3979192daf14340a6e to your computer and use it in GitHub Desktop.
Save bjorndarri/843afdd5400abe3979192daf14340a6e to your computer and use it in GitHub Desktop.
JConsole does not show threads when run via ProcessBuilder from the process being monitored (openjdk-11.0.2_linux-x64)
import java.io.File;
import java.io.IOException;
import java.util.concurrent.Executors;
public class JConsole11Test {
public static void main(String[] args) throws IOException {
Executors.newSingleThreadExecutor().execute(() -> {
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
});
String javaBin = System.getProperty("java.home") + System.getProperty("file.separator") + "bin";
new ProcessBuilder().directory(new File(javaBin))
.command("jconsole", getProcessId())
.start();
}
private static String getProcessId() {
return Long.toString(ProcessHandle.current().pid());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment