-2

i just want a Integer Value never duplicate in future i used it as temporary id in sqlite until get new id from mysql now what i used its

long temp_id = System.currentTimeMillis();

but when i want to add it to sqlite it must be an Integer so i convert it to int with

int temp idx = temp_id.intValue();

after i convert it to int did its possible to duplicate in future ? if its might duplicated any other idea for generate id never duplicate

medo zeus
  • 1
  • 1
  • 3
    [Monotonically increasing time in Java?](https://stackoverflow.com/q/434369/608639), [Will System.currentTimeMillis always return a value >= previous calls?](https://stackoverflow.com/q/2978598/608639), [Generate monotonically increasing integers](https://stackoverflow.com/q/8876255/608639), [Generating monotonically increasing integers (max 64bit)](https://stackoverflow.com/q/36396928/608639), etc. – jww Oct 10 '17 at 23:21

1 Answers1

1

either use a long as an id or simply let sqlite manage generating the ids for you which is the recommended way since it's both simpler and thread-safe (will never generate duplicate ids even when accessed from multiple threads)

Fminus
  • 61
  • 3