title: Simple ThreadPool implementation
body: <p>I want to understand logic of thread pool, and below there is a simple incorrect and not full implementation of it:</p>
  
  <pre><code>class ThreadPool {
      private BlockingQueue&lt;Runnable&gt; taskQueue;
  
      public ThreadPool(int numberOfThreads) {
          taskQueue = new LinkedBlockingQueue&lt;Runnable&gt;(10);
  
          for (int i = 0; i &lt; numberOfThreads; i++) {
              new PoolThread(taskQueue).start();
          }
      }
  
      public void execute(Runnable task) throws InterruptedException {
          taskQueue.put(task);
      }
  }
  
  
  class PoolThread extends Thread {
      private BlockingQueue&lt;Runnable&gt; taskQueue;
  
      public PoolThread(BlockingQueue&lt;Runnable&gt; queue) {
          taskQueue = queue;
      }
  
      public void run() {
          while (true) {
              try {
                  taskQueue.take().run();
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
  }
  </code></pre>
  
  <p>What if the number of threads to execute exceed the taskQueue size, will the calling thread be blocked?<a href="http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/util/concurrent/ThreadPoolExecutor.java?av=f" rel="nofollow">ThreadPoolExecutor</a> - here we can see that in this case it's a work of rejected execution handler, but I still can not understand how does it work. Thanks in advance for any help.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>set max size of blocking queue to 10</p>