gpt4 book ai didi

Java公平队列

转载 作者:行者123 更新时间:2023-11-30 04:29:11 27 4
gpt4 key购买 nike

我正在查看ArrayBlockingQueue

对于我可以传入构造函数的 fair 选项,公平实际上意味着什么?

fair - if true then queue accesses for threads blocked on insertion or removal, are processed in FIFO order; if false the access order is unspecified.

据我了解,公平意味着先进先出?不是我需要的?例如。 1 线程不应该一直访问队列吗?

最佳答案

FAIR is to implement a fair scheduling policyor to allow the implementation to choose one. Fair scheduling sounds like the better alternative, since it avoids the possibility that an unlucky thread might be delayed indefinitely but, in practice, the benefits it provides are rarely important enough to justify incurring the large overhead that it imposes on a queue's operation. If fair scheduling is not specified, ArrayBlockingQueue will normally approximate fair operation, but with no guarantees.

Reference with Code

关于Java公平队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15085335/

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