gpt4 book ai didi

java - 在这种情况下,为什么 Arrays.setAll 比 Arrays.parallelSetAll 更快?

转载 作者:行者123 更新时间:2023-12-02 07:59:04 24 4
gpt4 key购买 nike

在这种情况下,为什么 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com