This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes UID Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "UID" Watch "UID" New topic


shankar vembu
Ranch Hand

Joined: May 10, 2001
Posts: 309
Can I use java.rmi.dgc.VMID to generate a unique number even if i deploy my application in different hosts and /or environments. I have a web application which will deployed in an app server. SO i need to make sure that the UID i generate is unique even if i change my app server or my machine. Or if there is any other solution, pls let me know.
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 29219

According to the Javadoc:

Create a new VMID. Each new VMID returned from this constructor is unique for all Java virtual machines under the following conditions: a) the conditions for uniqueness for objects of the class java.rmi.server.UID are satisfied, and b) an address can be obtained for this host that is unique and constant for the lifetime of this object.

The significant constraint for UID is that the clock will never be turned back on the server. Assuming that is a reasonable assumption, you should be ok.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Don't get me started about those stupid light bulbs.
subject: UID
Similar Threads
Best way to generate PK in EJB
Sessions and Proxyserver problem
Application hangs with prior J2CA0086W warning messages
Uniqueness of UUID
Creating Unique Id