如何获取正在运行的 Java VM 的名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19165237/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 14:39:58  来源:igfitidea点击:

How can I get the name of running Java VM?

javajvm

提问by Shamim Ahmmed

How can I find the name of currently running java virtual machine name? I want to get it from java API.

如何找到当前运行的java虚拟机名称?我想从 java API 获取它。

Thanks

谢谢

采纳答案by Peter Lawrey

If you are trying to get the process id of the current process you can do this.

如果您正在尝试获取当前进程的进程 ID,您可以这样做。

How can a Java program get its own process ID?

Java 程序如何获得自己的进程 ID?

回答by Martijn Courteaux

Since you didn't really specify what you are looking for, take a look at these System Properties:

由于您并未真正指定要查找的内容,请查看以下系统属性:

  • "java.vm.name"
  • "java.home"
  • "java.version"
  • "java.vendor"
  • "java.specification.vendor"
  • "java.vm.name"
  • "java.home"
  • "java.version"
  • "java.vendor"
  • "java.specification.vendor"

Like this:

像这样:

System.out.println(System.getProperty("java.vm.name"));
System.out.println(System.getProperty("java.home"));
System.out.println(System.getProperty("java.vendor"));
System.out.println(System.getProperty("java.version"));
System.out.println(System.getProperty("java.specification.vendor"));

回答by user2842558

System.getProperty("java.version")should do the trick

System.getProperty("java.version")应该做的伎俩

回答by Denis Tulskiy

There is a variety of properties you can get with System.getProperty(), java.vm.nameseems like what you need.

您可以使用多种属性System.getProperty()java.vm.name似乎是您需要的。

回答by edwin moses ma

There are two kind of JVM names namely:

有两种JVM名称,即:

  1. Java Virtual Machine implementation name : Java HotSpot(TM) Client VM
  2. Java Virtual Machine specification vendor : Oracle Corporation
  1. Java 虚拟机实现名称:Java HotSpot(TM) Client VM
  2. Java 虚拟机规范供应商:Oracle Corporation

Type code in java program and see output:-

在java程序中输入代码并查看输出:-

 System.out.println("Java Virtual Machine specification version  : "+System.getProperty("java.vm.specification.version")); 
 System.out.println("Java Virtual Machine specification vendor : "+System.getProperty("java.vm.specification.vendor"));
 System.out.println("Java Virtual Machine specification name : "+System.getProperty("java.vm.specification.name"));
 System.out.println("Java Virtual Machine implementation version : "+System.getProperty("java.vm.version"));
 System.out.println("Java Virtual Machine implementation vendor : "+System.getProperty("java.vm.vendor"));
 System.out.println("Java Virtual Machine implementation name : "+System.getProperty("java.vm.name"));

refer https://docs.oracle.com/cd/E15289_01/doc.40/e15062/sysprop.htm

参考https://docs.oracle.com/cd/E15289_01/doc.40/e15062/sysprop.htm

see output of java -version

查看 java -version 的输出

To know ur JVM vendor: type java -versionin cmd and see third line of it.

要了解您的 JVM 供应商:输入java -versioncmd 并查看它的第三行。

eg:

例如:

C:\Users\Hyman>java -version

java version "1.8.0_74"

Java(TM) SE Runtime Environment (build 1.8.0_74-b02)

Java HotSpot(TM) Client VM (build 25.74-b02, mixed mode)

C:\Users\Hyman>java -version

java版本“1.8.0_74”

Java(TM) SE 运行时环境(构建 1.8.0_74-b02)

Java HotSpot(TM) 客户端 VM(构建 25.74-b02,混合模式)