[concurrency-interest] PriorityBlockingQueue question

Tim Peierls tim at peierls.net
Tue Sep 26 11:11:40 EDT 2006


On 9/26/06, Tim Peierls <tim at peierls.net> wrote:
>
> I'd like a way to clean up the scanForMatchingMessages() st/ it isn't
> > scanning. Any ideas?
>
>
> No ideas for this -- I'm thinking about the other approach.
>

What if you maintained a separate queue for each selector and atomically
marked messages when consumed? (You could use
AtomicMarkableReference.attemptMark, for example.) Then you don't have the
problem of having to remove a message from all other queues, since receivers
can simply ignore messages that someone else marked.

Then take(selector) is just "take from queue associated with selector" --
more precisely, repeatedly take until you can atomically mark an unmarked
message. I think you could use PBQs instead of PQs and a ConcurrentMap from
selector to queue, avoiding the need for a global lock.

Not sure of the desired behavior for messages that don't match any currently
waiting selector. Are they discarded? Left in their own queue for
selector-less consumption? Or do they have to be scanned for matches each
time you hear about a new selector? (In which case it might seem as though
you're almost back to the other approach, but maybe without the need for a
global lock.)

--tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20060926/b7654c59/attachment.html 


More information about the Concurrency-interest mailing list