• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unique identifier

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic