From 708893422d194224a9f8b984bb38d75730497a2c Mon Sep 17 00:00:00 2001 From: xyli Date: Fri, 3 Mar 2023 15:13:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20java=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=B5=8B=E8=AF=95=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/TestJvm.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/TestJvm.java b/src/test/java/TestJvm.java index cbb82f2..53c8d43 100644 --- a/src/test/java/TestJvm.java +++ b/src/test/java/TestJvm.java @@ -13,7 +13,26 @@ import java.util.Set; * Created by jiangzeyin on 2019/4/4. */ public class TestJvm { + public static void main(String[] args) throws IOException, AttachNotSupportedException, MonitorException, URISyntaxException { + System.out.println(SystemUtil.getJavaRuntimeInfo().getVersion()); + // 获取监控主机 + MonitoredHost local = MonitoredHost.getMonitoredHost("localhost"); + // 取得所有在活动的虚拟机集合 + Set vmlist = new HashSet(local.activeVms()); + // 遍历集合,输出PID和进程名 + for (Object process : vmlist) { + MonitoredVm vm = local.getMonitoredVm(new VmIdentifier("//" + process)); + // 获取类名 + String processname = MonitoredVmUtil.mainClass(vm, true); + System.out.println(processname); + if (!"io.jpom.JpomAgentApplication".equals(processname)) { + continue; + } + System.out.println(vm.getVmIdentifier().getUserInfo()); + System.out.println(vm.getVmIdentifier().toString()); + } + } } -- Gitee