gpt4 book ai didi

java - 数组排序方法行为

转载 作者:搜寻专家 更新时间:2023-10-31 19:33:15 24 4
gpt4 key购买 nike

我正在阅读“Java SE 8 for the really impatient”这本书,在第一章中我遇到了下一个练习题:

Is the comparator code in the Arrays.sort method called in the same thread as the call to sort or a different thread?

我在 javadoc 中搜索了带有 Comparator 参数的 Arrays.sort 重载,但它没有指定任何关于线程的信息。我假设出于性能原因,代码可以在另一个线程中执行,但这只是一个猜测。

最佳答案

您始终可以通过记录 Thread.currentThread()id 来测试它。

在调用 sort() 之前和您的 compare() 方法中添加一些内容。

logger.debug("Thread # " + Thread.currentThread().getId());

关于java - 数组排序方法行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23774057/

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