Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain unique JVM identifier?

Tags:

java

jvm

How can Java code obtain a unique identifier for the JVM in which it's running? On a Unix system, an example of what I'm looking for would be the PID of the process in which the JVM is running (assuming a one-to-one mapping between JVM's and processes).

like image 354
Steve Emmerson Avatar asked Nov 28 '11 21:11

Steve Emmerson


1 Answers

We have been using:

import java.lang.management.ManagementFactory;
String jvmName = ManagementFactory.getRuntimeMXBean().getName();

Which gives something like <pid>@<hostname>, at least in Sun/Oracle JVMs.

like image 177
Erik van Oosten Avatar answered Sep 28 '22 17:09

Erik van Oosten