title: Threads throwing RuntimeException - Impact on Threadpool
body: <p>I just read <a href="http://codeidol.com/java/java-concurrency/Cancellation-and-Shutdown/Handling-Abnormal-Thread-Termination/" rel="nofollow">this article</a> and thought that threadpool may run out of worker threads if the <code>Runnable</code>'s throw exception and exit. I did a small code and checked, but the poolsize didn't vary.</p>
  
  <pre><code>public class ThreadPoolTest {
  
  public static void main(String[] args) throws InterruptedException {
      ThreadPoolExecutor tp = new ThreadPoolExecutor(1, 1, 5, TimeUnit.SECONDS, new ArrayBlockingQueue&lt;Runnable&gt;(1));
      Thread.sleep(1000);
      System.out.println(tp.getPoolSize());
      tp.execute(new Runnable(){
  
          @Override
          public void run() {
              System.out.println("Executing &amp; Throwing");
              throw new NullPointerException();
          }
  
      });
      Thread.sleep(1000);
      System.out.println(tp.getPoolSize());
      tp.execute(new Runnable(){
  
          @Override
          public void run() {
              System.out.println("Executing &amp; Throwing");
              throw new NullPointerException();
          }
  
      });
      Thread.sleep(1000);
      System.out.println(tp.getPoolSize());
      tp.shutdown();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Output I got was</p>
  
  <pre><code>0
  Exception in thread "pool-1-thread-1" java.lang.NullPointerException
      at threads.ThreadPoolTest$1.run(ThreadPoolTest.java:18)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  Executing &amp; Throwing
  1
  Exception in thread "pool-1-thread-2" java.lang.NullPointerException
      at threads.ThreadPoolTest$2.run(ThreadPoolTest.java:29)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  Executing &amp; Throwing
  1
  </code></pre>
  
  <p>This is on Java 7. <strong>Is there any java Threadpool implementation which is vulnerable as stated in the article?</strong></p>