mardi 14 juillet 2015

ThreadLocalRandom or AtomicInteger

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

  1. Use AtomicInteger and share it across all threads
  2. 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