Get a unique identifier
java.rmi.dgc.VMID can generate an identifier.
Each new VMID is unique for all Java virtual machines under the following conditions:
- The conditions for uniqueness for objects of the class java.rmi.server.UID are satisfied
- An independently generated UID instance is unique over time with respect to the host it is generated
on as long as the host requires more than one millisecond to reboot and its system clock is never
set backward. A globally unique identifier can be constructed by pairing a UID instance with a unique
host identifier, such as an IP address.
- An address can be obtained for this host that is unique and constant for the lifetime of this object.
The format is :
[2 chars for each byte in 4 byte ip address]:
[8 char unique string]:
[16 char from time in hex]:
[8 char from count]
Code :
public class TestVMID {
public static void main(String arg[]) {
System.out.println(new java.rmi.dgc.VMID().toString());
System.out.println(new java.rmi.dgc.VMID().toString());
System.out.println(new java.rmi.dgc.VMID().toString());
}
}
Output :
d578271282b42fce:-2955b56e:107df3fbc96:-8000
d578271282b42fce:-2955b56e:107df3fbc96:-7fff
d578271282b42fce:-2955b56e:107df3fbc96:-7ffe
See also this HowTo
Written and compiled by Réal Gagnon ©1998-2005
[ home ]