Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unique identifier

 
Vikas Sahu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All,

I need unique identifier. For this I planning to use java.rmi.server.UID class.
Can any body tell me what s the maximum limit of this classss to give unique number.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the no-args constructor version includes a timestamp it can make unique ids until the end of time. Two machines could produce the same id, though, so they recommend adding the IP address to the UID to make them globally unique.
 
Chris Rutkowski
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if the IP address is assigned using DHCP? Then it wouldn't necessarily be unique. Can that cause problems?
 
Chris Beckey
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Can that (duplicate IP) cause problems?"
Well.. maybe. Since the UID uses a timestamp the addition of the IP would make the UIDs unique on that network, unless there was a duplicate IP in which case you have bigger problems. If, for instance, the IP was in a private network using NAT and therefore almost certainly not unique across the Internet, but you needed to generate unique UIDs across the Internet then you would need to find some unique ID for the machine. MAC address is a possibility but it is not accessible without writing JNI or some other kind of native code. Also, the MAC address can be spoofed. Still it is almost certainly sufficient and if rules about MAC cloning can be enforced it is definately sufficient.
If the domain of uniqueness can be restricted to a single application then another possibility is adding a hash of the user ID to the UID.
FWIW, I've used a combination of MAC address, Object.hashCode(), timestamp, and a serial number. The MAC address for machine uniqueness, the hashCode for process uniqueness, the timestamp for time uniqueness, and the serial number for multiple UIDs within the time granularity. With the addition of the MAC address this is close to the UID generation algorithm.
Our unit testing would generate 1,000,000 UIDs on 10 threads and then check them for duplicates and it never failed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic