how to get running jvms in current machine

允我心安 提交于 2019-12-20 06:24:16

问题


Imagine that: Two java projects are work on JDK1.5 and JDK1.6 Two are work on JDK 1.7. How to get the running jvm names, pids and projects name works on it.

the result should LOOKS LIKE:

pid 1234, projec_tname prj1, java_version JDK1.6

pid 4354, projec_tname prj2, java_version JDK1.5

pid 6234, projec_tname prj3, java_version JDK1.7

pid 9034, projec_tname prj4, java_version JDK1.7

Solution in Is there a Java library that searches for JVMs on the current machine? is find JDKs in current machine which not running. It is not helped for my question. Any ideas?


回答1:


You are looking for this API: http://docs.oracle.com/javase/7/docs/jdk/api/attach/spec/

You have to add the tools.jar to your classpath.

This is the method to start with: VirtualMachine.list()

The id()s are provider specific but it’s usually a process id.



来源:https://stackoverflow.com/questions/18509101/how-to-get-running-jvms-in-current-machine

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!