I have a need to generate non-overlapping numbers (random or incremental doesnt matter as each generated number is unique) in multiple threads. I think I have two choices
- Use AtomicInteger and share it across all threads
- Use ThreadLocalRandom with different start and end ranges for each thread
I need this to be very fast and also the numbers should be unique across all the threads. Which one is better?
Aucun commentaire:
Enregistrer un commentaire