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
public class TestUUID {
public static void main(String arg[]) {
System.out.println(java.util.UUID.randomUUID());
// output : dedc3f57-6ce1-4504-a92f-640d8d9d23c9
}
}
This is probably the preferred method.
Mini-FAQ on the subject : http://www.asciiarmor.com/post/33736615/java-util-uuid-mini-faq
import java.util.concurrent.AtomicLong;
public class Descriptor {
private static final AtomicLong nextId = new AtomicLong();
private static long nextId() {
return nextId.getAndIncrement();
}
}
See also this HowTo for unique numerical id based on the system time.
Written and compiled by Réal Gagnon ©1998-2010
[ home ]