Reputation: 14702
I need to uniquely identify messages in my app. Thus each message should contain its id. I have a couple of questions though..
Thanks.
Upvotes: 3
Views: 2355
Reputation: 346260
AtomicInteger
or AtomicLong
are good alternatives that can be used concurrectly without locking.Upvotes: 6
Reputation: 96716
Without more context I would answer: if you are concerned about speed, you could always have a process (on an other machine?) pre-compute the UUIDs for the application. This way, the application could have quick access to a "pool" of UUIDs.
One shouldn't be able to the change the UID of a message or else what is the point?
What's wrong with UUID class ? if it is about speed, then see above.
Upvotes: 2