本文介绍了如何在当前机器上运行jvm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下:两个Java项目正在JDK1.5和JDK1.6上运行有两个在JDK 1.7上进行.如何获取正在运行的jvm名称,pid和项目名称就可以了.

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

结果应该看起来像:

pid 1234,projec_tname prj1,java_version JDK1.6

pid 1234, projec_tname prj1, java_version JDK1.6

pid 4354,projec_tname prj2,java_version JDK1.5

pid 4354, projec_tname prj2, java_version JDK1.5

pid 6234,projec_tname prj3,java_version JDK1.7

pid 6234, projec_tname prj3, java_version JDK1.7

pid 9034,projec_tname prj4,java_version JDK1.7

pid 9034, projec_tname prj4, java_version JDK1.7

中的解决方案在当前计算机上搜索Java的Java库?是在当前计算机上未运行的JDK中找到的.我的问题无济于事.有什么想法吗?

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?

推荐答案

您正在寻找以下API: http://docs.oracle.com/javase/7/docs/jdk/api/attach/spec/

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

您必须将tools.jar添加到您的类路径中.

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

这是从以下位置开始的方法: VirtualMachine.list()

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

id()是特定于提供程序的,但通常是进程ID.

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

这篇关于如何在当前机器上运行jvm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 01:47