[concurrency-interest] ExecutorCompletionService is dangerous for critical app!!

yangjs yangjs at alibaba-inc.com
Fri Aug 11 01:38:12 EDT 2006


hi,all

   I  use ExecutorCompletionService in my app ,that is a producer-consumer pattern. code like follow:

    blic ExecutorCompletionService jobQueue = new ExecutorCompletionService<Document>(
     getThreadExecutor(), getBlockingQueue(100));

  I found when ExecutorCompletionService found queue full,then the finished job was discarded.
  after read the implement code ,the ExecutorCompletionService implments the QueueingFuture as follow:

      private class QueueingFuture extends FutureTask<V> {
          QueueingFuture(Callable<V> c) { super(c); }
          QueueingFuture(Runnable t, V r) { super(t, r); }
          protected void done() { completionQueue.add(this); }
      }

     when queue  full, completionQueue.add(this) will throw exception but swallowed by Future self.so the task will disappear,this is very dangerous for my critical app.

   why use completionQueue.add(this) ,why not use completionQueue.put(this),this is a block method , we want use throttling strategy when queue is full,I will implement self ,like this :


      private class QueueingFuture extends FutureTask<V> {
          QueueingFuture(Callable<V> c) { super(c); }
          QueueingFuture(Runnable t, V r) { super(t, r); }
          protected void done() { completionQueue.put(this); }
      }


  is right?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20060811/a47c83ab/attachment.html 


More information about the Concurrency-interest mailing list