title: spring integration task executor queue filled with more records
body: <p>I started to build a Spring Integration app, in which the input gateway generates a fixed number (50) of records and then stops generating new records. There are basic filters/routers/transformers in the middle, and the ending service activator and task executor config are as following:</p>
  
  <pre><code>&lt;int:service-activator input-channel="inChannel" output-channel="outChannel" ref="svcProcessor"&gt;
          &lt;int:poller fixed-rate="100" task-executor="myTaskExecutor"/&gt;
  &lt;/int:service-activator&gt;
  
  &lt;task:executor id = "myTaskExecutor" pool-size="5" queue-capacity="100"/&gt;
  </code></pre>
  
  <p>I tried to put some debug info at the begging of the svcProcessor method:</p>
  
  <pre><code>@Qualifier(value="myTaskExecutor")
  @Autowired 
  ThreadPoolTaskExecutor executor;
  
  @ServiceActivator
  public Order processOrder(Order order) {
    log.debug("---- " + "executor size: " + executor.getActiveCount() + 
          " q: " + executor.getThreadPoolExecutor().getQueue().size() + 
          " r: " + executor.getThreadPoolExecutor().getQueue().remainingCapacity()+
          " done: " + executor.getThreadPoolExecutor().getCompletedTaskCount() +
          " task: " + executor.getThreadPoolExecutor().getTaskCount()
      );
     //
     //process order takes up to 5 seconds.
     //
     return order;
  }
  </code></pre>
  
  <p>After sometimes the program runs, the log shows the queue has reached over 50, then eventually gets reject exception:</p>
  
  <pre><code>23:38:31.096 DEBUG [myTaskExecutor-2] ---- executor size: 5 q: 44 r: 56 done: 11 task: 60
  23:38:31.870 DEBUG [myTaskExecutor-5] ---- executor size: 5 q: 51 r: 49 done: 11 task: 67
  23:38:33.600 DEBUG [myTaskExecutor-4] ---- executor size: 5 q: 69 r: 31 done: 11 task: 85
  23:32:46.792 DEBUG [myTaskExecutor-1] ---- executor size: 5 q: 72 r: 28 done: 11 task: 88
  </code></pre>
  
  <p>It looks like the active count and sum of queue size/remaining looks right with the config of 5 and 100, but I am not clear why there are more than 50 records in the queue, and the taskCount is also larger than the limit 50.</p>
  
  <p>Am I looking at the wrong info from the executor and the queue?</p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATE:</strong> 
  (not sure if I should open another question)</p>
  
  <p>I tried the xml version of the cafeDemo from spring-integration (branch SI3.0.x), and used pool provided in the document, but used 100 milliseconds rate and added capacity:</p>
  
  <pre><code>&lt;int:service-activator input-channel="hotDrinks" ref="barista" method="prepareHotDrink" output-channel="preparedDrinks"&gt;
      &lt;int:poller task-executor="pool" fixed-rate="100"/&gt;          
  &lt;/int:service-activator&gt;
  &lt;task:executor id="pool" pool-size="5" queue-capacity="200"/&gt;
  </code></pre>
  
  <p>After I ran it, it also got rejection exception after around the 20th delivery:</p>
  
  <pre><code> org.springframework.core.task.TaskRejectedException: Executor [java.util.concurrent.ThreadPoolExecutor@6c31732b[Running, pool size = 5, active threads = 5, queued tasks = 200, completed tasks = 0]]
  </code></pre>
  
  <p>There are only about 32 orders placed until the exception, so I am not sure why queued tasks = 200 and completed task = 0?</p>
  
  <p>THANKS</p>