Detect current JVM using Java or JVMTI

I would like to identify the current JVM that is starting. In the best case, with the function described in the JVMTI Documentation , but I can not find anything.


What I had in mind is something like this: VirtualMachine.list()provides:

[sun.tools.attach.WindowsAttachProvider@46ae506e: 2440 de.fu.profiler.view.MainFrame...

But it displays all the JVM, not the current one.

+2
source share
5 answers

You can get a unique name from RuntimeMXBean . on most platforms, this includes the processid of the current process.

+3
source

Use Java system properties like

java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition
java.runtime.version=1.5.0_01-b08
java.specification.name=Java Platform API Specification
java.specification.vendor=Sun Microsystems Inc.
java.specification.version=1.5
java.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi
java.version=1.5.0_01
java.vm.info=mixed mode, sharing
java.vm.name=Java HotSpot(TM) Client VM
java.vm.specification.name=Java Virtual Machine Specification
java.vm.specification.vendor=Sun Microsystems Inc.
java.vm.specification.version=1.0
java.vm.vendor=Sun Microsystems Inc.
java.vm.version=1.5.0_01-b08

Use java.lang.System.getProperties()orgetProperty(String name)

+3
source

System.getProperty("java.runtime.name") ?

0

JVM , , , , .

JVMTI, , JVM, . , , JVM () . . , , JVM (, java.lang.) (, com.fun.). "" JVM.

-1

Source: https://habr.com/ru/post/1523873/


All Articles