[concurrency-interest] Bulk queue operations
Tue, 21 Dec 2004 17:29:22 -0500
David Holmes wrote:
>>Could you tell me why Queue or BlockingQueue don't provide atomic bulk
>>operations like offerMany, putMany and takeMany?
> If the intent of these bulk operations is to offer/put/take the next n
> elements - ensuring no other producers/consumers get to touch the queue in
> between - then only certain types of implementation can easily support such
> semantics ie lock-based implementations. Such operations would have to be
> defined in a seperate interface to avoid burdening all Queue and
> BlockingQueue implementations. Such an interface wasn't defined because
> there was no real requirement for it at the time.
> If the intent is not to enforce ordering, then looping on the existing
> offer/put/take methods achieves the same thing.
Personnaly, I don't need to enforce ordering because my consumers can
reorder taken items. But it could be useful for other applications.
I would be happy to have Bulk-Queue stuff in jsr166x/JDK6 because I have
the impression that a 'putMany' with a 'takeMany' operations could be
more efficient than many 'put' with many 'take'. Also, we could want to
offer many objects atomically.