[concurrency-interest] LinkedBlockingQueue and iterator question

ray hanmlw at gmail.com
Wed Oct 26 22:24:23 EDT 2005

>I'm not clear what your requirements are. You say you want to iterate
>objects IN the queue, but at the same time you are allowing the queue to be
>modified concurrently - these conflict. You cannot guarantee that an item
>returned by the iterator (or through an entry in toArray()) is still in
>queue at the time you access it - you only know that it was in the queue.
This is exactly my requirements. Now I see it's impossible using 
LinkedBlockingQueue. Thanks!

>If you need to exclude access to the queue while iterating you need a
>higher-level protocol to provide that in your application. The simplest way
>to get such a protocol is to not use a concurrent data structure like
>LinkedBlockingQueue but, for example, a synchronizedList wrapping a
One reason I use LinkedBlockingQueue is that it implements 
BlockingQueue. Maybe I should write my data structure which extends 
LinkedList and implements BlockingQueue.


More information about the Concurrency-interest mailing list