[concurrency-interest] Queue throughput

David Holmes dholmes@dltech.com.au
Fri, 5 Nov 2004 15:46:35 +1000

> Jean Morissette writes:
> Javadoc of BlockingQueue interface says about drainTo that "this
> operation may be more efficient than repeatedly polling this queue".  Is
> it really more efficient for LinkedBlockingQueue class?  It seem to me
> that 'drainTo' can reduce throughput (compared to poll method) because
> it acquire also the "putLock".

It says *may* be more efficient. Whether it is or not depends entirely on
how you use it. For the thread doing the drainTo it will almost certainly be
more efficient than repeated polling. However, that need not translate to
improving efficiency of the application (however you want to define
efficiency for the application) as it will potentially impact on producers.

David Holmes