title: What are disadvantages of using ThreadPoolExecutor as queue?
body: <p>For conventional Producer-Consumer problem, we can use ExecutorService as queue. What are disadvantages of it? Is it less efficient? Because creation of thread is costly.</p>
  
  <pre><code>executor = Executors.newFixedThreadPool(90);
  // This will be called many times concurrently
  public void processObjectsWithFixedSetOfThreads(Foo objectToProcess) {
     //Create a new thread and submit (executor is of fixed size hence extra tasks will be queued)
     executor.submit(new ObjectProcessorWorker(objectToProcess));
  }
  
  class ObjectProcessorWorker implements Runnable() {
    public ObjectProcessorWorker(Foo obj) {
       this.obj = obj;
    }
  
    public void run() {
       longRunningProcess(obj);
    }
  
  }
  </code></pre>
  
  <p>Why <a href="https://github.com/TheNilesh/asyncmodel/blob/master/asyncmodel/src/main/java/com/nilesh/asyncmodel/blockingqueue/Worker.java" rel="nofollow">BlockingQueue</a> is recommended for Producer-Consumer problem however it can be done <a href="https://github.com/TheNilesh/asyncmodel/tree/master/asyncmodel/src/main/java/com/nilesh/asyncmodel/executorservice" rel="nofollow">without that</a> too (As shown above)?</p>
  
  <h2>EDIT</h2>
  
  <p>Many people are not getting the difference because ThreadPoolExecutor internally maintains the BlockingQueue.</p>
  
  <p>In a biscuit factory there is a task of wrapping biscuits. If I am its owner I have two ways to speed up wrapping task.</p>
  
  <ol>
  <li><p>Put biscuits and wrapper on assembly line have 10 workers doing work of wrapping.</p>
  
  <p>I -> <code>queue.put(biscuits, wrapper)</code></p>
  
  <p>Worker -> <code>queue.take()</code></p></li>
  <li><p>Creating a task of wrapping biscuits putting it on a assembly line, and let the 10 workers do that.</p>
  
  <p>I -> <code>new Task(biscuits, wrapper)</code></p>
  
  <p>Worker -> <code>task = queue.take(); do(task);</code></p></li>
  </ol>
  
  <p>I am asking the disadvantages of the later one.</p>