Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

using java.util.UUID

 
Ranch Hand
Posts: 35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
required - a UUID to be passed in XML / stored in database.

i saw java 5 has a new class for this.

Wanted to know if my usage was the good:



my question is that is my assumption that the full UUID as a string is :


if i do not Math.abs the LeastSignificantBits then I get a negative number there sometimes. does not look right ... its fine and expected if the complete number is negative at times...


also this UUID takes a few milliesconds to generate and I saw that this class is a little faster:


question - is this method unsafe? can the combination of currentTimeMillis, System.nanoTime() (new in java 1.5) and rnd.nextLong() not be unique?

its for a j2ee app that runs all the time and has quite a few transactions...
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're putting it in a DB anyway, why not use a sequence?
 
Tushar Kapila
Ranch Hand
Posts: 35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
need it in xml before that. just assume that a db is not available when i need to generate , pass this around
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of using a random Unique number like this, if you can generate some unique number according to your xml data (may be by adding time or getting some sequence value from db or some internal sequence maintained) will be better, as it can be used for different purposes like the order of xml generation, etc.
 
Marshal
Posts: 65755
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch ( ) Gokul Nanthakumar
 
Tushar Kapila
Ranch Hand
Posts: 35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gokul Nanthakumar wrote:Instead of using a random Unique number like this, if you can generate some unique number according to your xml data (may be by adding time or getting some sequence value from db or some internal sequence maintained) will be better, as it can be used for different purposes like the order of xml generation, etc.

its for a financial transaction and it must be unique, not in our system alone but in the other parties as well.

i really want to know if the method of using Java's UUID is OK?



 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How on earth can you make a unique identifier that's unique *everywhere*???
 
Tushar Kapila
Ranch Hand
Posts: 35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Newton wrote:How on earth can you make a unique identifier that's unique *everywhere*???



From java.util.UUID javadoc "A class that represents an immutable universally unique identifier (UUID). A UUID represents a 128-bit value. "

internally they use a java.security.SecureRandom - which does a lot of nifty things if you ( looked inside src.zip)



 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a namespaced-variant is being used, maybe; I don't believe you could rely on the random-number variant, though (as per the RFC).
 
Tushar Kapila
Ranch Hand
Posts: 35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Newton wrote:If a namespaced-variant is being used, maybe; I don't believe you could rely on the random-number variant, though (as per the RFC).



by namespaced variant - do you mean - take part of the UUID from my data and append it to the UUID?

psuedo code :

 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!