"Aren't allocating the things put into queues" 是什么意思?
What does "Aren't allocating the things put into queues" mean?
我正在读这个:
其中 Doug Lea 说:
Usually, when you are putting something into a queue, you will have
just allocated that new something. And similarly, when you take
something out you usually use it and then let it become garbage. In
which case the extra allocation for a queue node is not going to make
much difference in overall GC, so you might as well go for the better
scalability of LinkedBlockingQueue. I think this is the most common
use case.
But, if you aren't allocating the things put into queues, and don't
expect lots of threads to be contending when the queue is neither
empty nor full, then ArrayBlockingQueue is likely to work better.
我想知道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
,有人可以更具体地解释一下吗?
对我来说这似乎意味着以下内容:
-
I want to know what does Aren't allocating the things put into queues
mean?
这是关于他们讨论的 GC 开销。
LinkedBlockingQueue
为每个添加的项目创建 new internal Node
object,这意味着它会产生垃圾,并因此导致垃圾收集 (GC)。
Doug 说,我们存储在队列中的项目通常是以下对象:
- 在添加到队列之前创建
- 它们从队列中移除后不久变为未使用(并符合 GC 条件)
在这些情况下,项目本身无论如何都会导致 GC,因此 Node
对象也需要 GC 不是问题。
但是如果你只在队列中存储长期存在的对象,那么 LinkedBlockingQueue
可能成为唯一导致 GC 的东西。
那么您可能想使用 ArrayBlockingQueue
来避免 GC。
(ArrayBlockingQueue
项目 added/removed 时不创建任何对象)
-
Also, this sentence: don't expect lots of threads to be contending when the queue is neither empty nor full, then ArrayBlockingQueue is likely to work better
, can someone explain that a little bit more specifically?
LinkedBlockingQueue
uses two locks:一个用于 put()
,一个用于 take()
。
ArrayBlockingQueue
uses one lock 对于 put()
和 take()
。
结果当“the queue is neither empty nor full
”(即当 put()
和 take()
都不必等待时)并且有两个线程:一个执行 put()
,另一个执行 take()
- 如果队列是
LinkedBlockingQueue
,那么线程不会互相阻塞
- 如果队列是
ArrayBlockingQueue
,那么一个线程将不得不等待另一个线程完成
我正在读这个:
其中 Doug Lea 说:
Usually, when you are putting something into a queue, you will have just allocated that new something. And similarly, when you take something out you usually use it and then let it become garbage. In which case the extra allocation for a queue node is not going to make much difference in overall GC, so you might as well go for the better scalability of LinkedBlockingQueue. I think this is the most common use case.
But, if you aren't allocating the things put into queues, and don't expect lots of threads to be contending when the queue is neither empty nor full, then ArrayBlockingQueue is likely to work better.
我想知道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
,有人可以更具体地解释一下吗?
对我来说这似乎意味着以下内容:
-
I want to know what does
Aren't allocating the things put into queues
mean?这是关于他们讨论的 GC 开销。
LinkedBlockingQueue
为每个添加的项目创建 new internalNode
object,这意味着它会产生垃圾,并因此导致垃圾收集 (GC)。
Doug 说,我们存储在队列中的项目通常是以下对象:- 在添加到队列之前创建
- 它们从队列中移除后不久变为未使用(并符合 GC 条件)
在这些情况下,项目本身无论如何都会导致 GC,因此
Node
对象也需要 GC 不是问题。但是如果你只在队列中存储长期存在的对象,那么
LinkedBlockingQueue
可能成为唯一导致 GC 的东西。
那么您可能想使用ArrayBlockingQueue
来避免 GC。
(ArrayBlockingQueue
项目 added/removed 时不创建任何对象) -
Also, this sentence:
don't expect lots of threads to be contending when the queue is neither empty nor full, then ArrayBlockingQueue is likely to work better
, can someone explain that a little bit more specifically?LinkedBlockingQueue
uses two locks:一个用于put()
,一个用于take()
。
ArrayBlockingQueue
uses one lock 对于put()
和take()
。
结果当“the queue is neither empty nor full
”(即当put()
和take()
都不必等待时)并且有两个线程:一个执行put()
,另一个执行take()
- 如果队列是
LinkedBlockingQueue
,那么线程不会互相阻塞 - 如果队列是
ArrayBlockingQueue
,那么一个线程将不得不等待另一个线程完成
- 如果队列是