[concurrency-interest] More control on 'full' with blockingqueue.

Peter Veentjer - Anchor Men p.veentjer at anchormen.nl
Sun Aug 7 13:45:32 EDT 2005


I've not had the same problem, but if I'm understanding you correctly, it
seems that a nice solution might be something along the lines of the

Modify the various offer() and take() (and related) calls to accept a
weight parameter (which would also need to be added into the Node class
(see the insert() method). In your case, you'd supply this as a function
of the document length. Then, instead of using getAndIncrement() and
getAndDecrement() calls inside offer() and take(), use getAndAdd() (which
can take a negative operand) to add the weight of the current document.
This could be a solution and this would give an indication for the remaining capacity.
The advantage of totally externalizing the 'isfull' functionality is
- I can share the instance between multiple queues and this make communication between them possible.
- It is less restrictive. It doesn`t impose a numeric weight to each item. It seperates the what from the how better I think.

If you need help getting this blocking queue variant working, let me know.
Thanks for the offer, but I already have implemented a version based on the LinkedBlockingQueue. Maybe you want to have a look at it?

And do you know if there are extensions available for the concurrency library? For the Collection Framework there are numerous extensions available, but I haven`t found any for the concurrency library.

More information about the Concurrency-interest mailing list