Monday, November 14

UUID Generators

In my J2EE world, every now and then I am asked to generate sets of a few hundreds/thousands of unique Strings -for reasons such as unique identification of vouchers sent. I usually *borrow* code that has been widely used and tested, such as Hibernate's UUIDHexGenerator or Tomcat's session id generator, the choice depending on the requirements for the String size.
Well, for future reference, here's a link to a very useful (and open-source) UUID generator library:

http://jug.safehaus.org/

String are
128-bit Universally Unique IDentifiers according to the IETF UUID draft specification. To give an example, generated Strings can look like this: a02c73a6-b8c9-46e9-a368-8b9f9ef8ff7f

[Update]
From this thread on Jason Carreira's blog, I found out about J-GUID by Steve Woodcock, whose code is currently used as the UUID generator in the XDoclet project.
Darren Hobbs usefully points out that Java has built-in GUID generation:
java.rmi.server.UID (unique over time within a JVM) and java.rmi.dgc.VMID (unique across all JVM's).
Finally, and to our utter joy, the JDK 5.0 already ships with a built-in UUID package.

No comments: