I am generating unique ID for objects to be stored
i am including the timestamp in it
but i ran the for loop
for (int i = 0; i < 100; i++) {
long time = Calendar.getInstance().getTimeInMillis();
st = Integer.toHexString((int) time);
System.out.printf("%d %s %d %n", i, st, st.length());
}
I am not getting the Unique
I inserted Thread.sleep(15) , then it is giving me unique value
is there another way i get the unique value?
I’d use a simple
longorint.AtomicLong.incrementAndGetis more simple and it’s thread-safe.Another possibility is using UUID.randomUUID() but it’s an UUID, not an numeric value.