【发布时间】:2021-12-08 00:46:20
【问题描述】:
我在读这个:
Doug Lea 说:
通常,当您将某物放入队列时,您将拥有 刚刚分配了新的东西。同样,当你采取 一些你通常使用它然后让它变成垃圾的东西。在 在这种情况下,队列节点的额外分配不会产生 整体 GC 差异很大,所以你最好做得更好 LinkedBlockingQueue 的可扩展性。我认为这是最常见的 用例。
但是,如果您不分配放入队列中的东西,并且不要 当队列两者都不是时,预计会有很多线程竞争 空也不满,那么 ArrayBlockingQueue 可能会更好地工作。
我想知道Aren't allocating the things put into queues是什么意思?
另外,这句话:don't expect lots of threads to be contending when the queue is neither empty nor full, then ArrayBlockingQueue is likely to work better,有人能具体解释一下吗?
【问题讨论】:
-
从上下文来看,这似乎意味着您放入队列中的东西是否长期存在,即很久以前有人已经分配了它们。
标签: java multithreading concurrency java.util.concurrent