Generating globally unique IDs in a clustered, distributed environment is a common application requirement. A simple way is to combine the following four parts together.
Unique to the System.currentTimeMillis()
Unique to the IP address
Unique to the object instance System.identityHashCode(this)
Unique within a millisecond, SecureRandom
All ints and longs will be converted to a hex string of length 8.
A open source named Java UUID Generator is available at http://jug.safehaus.org/.
No comments:
Post a Comment