[concurrency-interest] Is there a ConcurrentBlockingQueue ??

Hanson Char hanson.char at gmail.com
Mon Mar 19 23:25:31 EDT 2007


Have you checked this out ?

    http://hansonchar.blogspot.com/2006/09/concurrentlinkedblockingqueue.html

Cheers,
Hanson

On 3/19/07, Rajesh Balamohan <rajesh.balamohan at gmail.com> wrote:
> Hi All,
>
> We are using LinkedBlockingQueue since it blocks on take() method. We have a
> requirement like the following.
>
> 1. Many tasks are submitted to a threadpool by different threads. The task
> internally adds some item to a LinkedBlockingQueue. I have striped down most
> of the logic below. Please ignore the contents as such.
>
> //The following task will be submitted by a pool of threads to a
> threadPoolExecutor.
>  static class Request implements Runnable {
>
>         MessageState state = new MessageState();
>
>         public void run() {
>             synchronized (state) {
>                 if (!state.isRequestStarted()) {
>
> state.addEvent(MessageState.EVENT.REQUEST_RECEIVE_COMPLETE);
>                 }
>             }
>              myLinkedBlockingQueue.add(state);
>         }
>     }
>
> 2. One reaper thread is created whose job is to keep on taking out the items
> from the LinkedBlockingQueue (basically like the following)
>
> while(true) {
>   accept();
> }
>
> private void accept() {
>   try {
>      MyItem item = myLinkedBlockingQueue.take();
>  } ...blah blah...
> ..........
> ......
> do necessary processing.
> }
>
>
>  Now, I feel that it should be ConcurrentLinkedQueue instead of
> LinkedBlockingQueue. ConcurrentLinkedQueue might be able to scale well than
> LinkedBlockingQueue for multiple threads.
>
> Problem is ConcurrentLinkedQueue doesn't have a blocking take(). Are there
> any plans to add it? Or you think that this problem can be solved
> differently?
>
> --
> ~Rajesh.B
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>


More information about the Concurrency-interest mailing list