Is it possible to get a truly unique id for a particular JVM instance?

Posted by Uri on Stack Overflow See other posts from Stack Overflow or by Uri
Published on 2010-05-14T14:10:43Z Indexed on 2010/05/15 0:04 UTC
Read the original article Hit count: 136

Filed under:
|
|

I need a way to uniquely and permanently identify an instance of the JVM from within Java code running in that JVM.

That is, if I have two JVMs running at the same time on the same machine, each is distinguishable. It is also distinguishable from running JVMs on other machines and from future executions on the same machine even if the process id is reused.

I figure I could implement something like this by identifying the start time, the machine MAC, and the process id, and combining them in some way. I'm wondering if there is some standard way to achieve this.

Update: I see that everyone recommended a UUID for the entire session. That seems like a good idea though possibly a little too heavyweight. Here is my problem though: I want to use the JVM id to create multiple unique identifiers in each JVM execution that somehow incorporate the JVM instance.

My understanding is that you shouldn't really mix other numbers into a UUID because uniqueness is no longer guaranteed. An alternative is to make the UUID into a string and chain it, but then it becomes too long. Any ideas on overcoming this?

© Stack Overflow or respective owner

Related posts about java

Related posts about jvm