[concurrency-interest] Re: Unbounded blocking queues -memory
cnmaclean at hotmail.com
Fri Oct 7 09:37:51 EDT 2005
I was thinking of implementations other than linked-list style. For
example, there's an ArrayBlockingQueue, which would presumably take up less
memory, but that's fixed capacity.
I'm wondering if there's any middle ground - unbounded, but minimal memory.
"Doug Lea" <dl at cs.oswego.edu> wrote in message
news:434676BA.7090500 at cs.oswego.edu...
> Calum MacLean wrote:
>> My application is producing a large unbounded quantity of objects which
>> are being put into a BlockingQueue for consumption by some other thread.
>> I'm currently using LinkedBlockingQueue, as it's unbounded.
>> However, I'm seeing that the LinkedBlockingQueue.Node objects take up a
>> fair bit of memory - around about 16 bytes each according to my profiler.
>> So, while I'm not 100% sure, I'm a bit worried about the memory
>> consumption, as it's a large number of objects which are being produced.
>> Are there any other alternatives for unbounded BlockingQueue
>> implementations which maybe take up less memory than LinkedBlockingQueue?
> I don't believe there is any way to reduce overhead for any
> linked structure down and further -- the nodes only have item
> and next fields; plus the usual Java per-Object header etc.
> If you really need the space and are in full control of the
> kinds of elements, you might be able to make a custom version.
> If for example, each element is of class Element, you can add
> a "next" link to the Element class, used only by the queue, and
> then copy-paste-hack LinkedBlockingQueue to directly use it
> rather than wrapping each item in a Node. This is not recommended
> unless you are desparate though.
More information about the Concurrency-interest