在这种情况下,为什么 Arrays.setAll 比 Arrays.parallelSetAll 更快?
int[] array = new int[30000000];
Random rnd = new Random();
Arrays.parallelSetAll(array, i->rnd.nextInt(200));
最佳答案
来自 javadoc:
Instances of java.util.Random are threadsafe. However, the concurrent use of the same java.util.Random instance across threads may encounter contention and consequent poor performance. Consider instead using ThreadLocalRandom in multithreaded designs.
关于java - 在这种情况下,为什么 Arrays.setAll 比 Arrays.parallelSetAll 更快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47355989/