title: High thread count in java thread dump
body: <p>My java web application running on <code>wildfly-9.0.1.Final</code> sometimes it consumes very high memory and CPU.
  I got the thread dump for this time and found more than 7K thread with an identical thread with below stack trace. </p>
  
  <pre><code>pool-47940-thread-1 - priority:5 - threadId:0x000000029ad3f800 - nativeId:0xfad0 - state:WAITING
  stackTrace:
  java.lang.Thread.State: WAITING (parking)
  at sun.misc.Unsafe.park(Native Method)
  - parking to wait for &lt;0x00000007a7d1fbe0&gt; (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  at java.lang.Thread.run(Thread.java:745)
  Locked ownable synchronize
  </code></pre>
  
  <p>I analyze thread dump using <a href="http://fastthread.io" rel="nofollow noreferrer">this</a> </p>
  
  <p>Here is a screenshot for the same. 
  <a href="https://i.stack.imgur.com/Q3lZv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q3lZv.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/B0JN2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B0JN2.png" alt="enter image description here"></a></p>
  
  <p>I used below code in my application many times</p>
  
  <pre><code>ExecutorService executor = Executors.newFixedThreadPool(3);
  //business logic
  // This will make the executor accept no new threads and finish all existing threads in the queue
  executor.shutdown();
  // Wait until all threads are finish
  while (!executor.isTerminated()) {
  
  }
  </code></pre>
  
  <p>Is ablow code cause any issue?</p>
  
  <p>Are this threads root cause for high memory and CPU usage?</p>