[concurrency-interest] Is there a ConcurrentBlockingQueue ??

David Holmes dcholmes at optusnet.com.au
Mon Mar 19 23:18:26 EDT 2007


As Joe Seigh just posted earlier today, you can use a Semaphore with a ConcurrentLinkedQueue to get a BlockingQueue version.

I can't comment as to whether that scales better or worse than LinkedBlockingQueue.

David Holmes
  -----Original Message-----
  From: concurrency-interest-bounces at cs.oswego.edu [mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Rajesh Balamohan
  Sent: Tuesday, 20 March 2007 12:55 PM
  To: Concurrency-interest at cs.oswego.edu
  Subject: [concurrency-interest] Is there a ConcurrentBlockingQueue ??


  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 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20070320/9a7a8a9a/attachment.html 


More information about the Concurrency-interest mailing list