title: How to stop all runnable thread in java executor class?
body: <pre><code>final ExecutorService executor = Executors.newFixedThreadPool(1);
  final Future&lt;?&gt; future = executor.submit(myRunnable);
  executor.shutdown();
  if(executor.awaitTermination(10, TimeUnit.SECONDS)) {
    System.out.println("task completed");
  }else{
    System.out.println("Executor is shutdown now");
  }
  
  //MyRunnable method is defined as task which I want to execute in a different thread.
  </code></pre>
  
  <p>Here is <code>run</code> method of executor class:</p>
  
  <pre><code>public void run() {
  try {
       Thread.sleep(20 * 1000);
  } catch (InterruptedException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }}
  </code></pre>
  
  <p>Here it is waiting for <code>20</code> second but when i run the code it throws an exception:</p>
  
  <pre><code>java.lang.InterruptedException: sleep interrupted
  at java.lang.Thread.sleep(Native Method)
  </code></pre>
  
  <p>I am not able to close the concurrent thread ruining in <code>Java Executor class</code>. Here is my Code flow:</p>
  
  <ul>
  <li>Created a new Thread with Java executor class to run some task i.e written in <code>MyRunnable</code></li>
  <li><code>executor</code> wait for 10 second to complete the tasks.</li>
  <li>If the task has completed then runnable thread also got terminated.</li>
  <li>If the task is not completed within 10 second then <code>executor</code> class should terminate the thread.</li>
  </ul>
  
  <p>Everything works fine except the termination of tasks in the last scenario. How should I do it? </p>