Which of these correctly obtains a random number generator intended for concurrent use?
Answer: C
Correct answer: ThreadLocalRandom.current().nextInt(10)
ThreadLocalRandom gives each thread its own generator, which removes the contention that a shared Random suffers under concurrency. The instance is reached through the static current(); the class cannot be instantiated directly, and the generating methods are not themselves static.
Please log in or register to report this question.