Created
January 22, 2019 14:42
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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