title: how to kill hung thread in java
body: <p>I have been trying to kill thread which are hung due to heavy IO operation.
  I could have tried <code>thread.destroy</code> or <code>thread.stop</code> but they have been deprecated
  For example have a look at below code</p>
  
  <pre><code>public class ThreadCheck {
  private static int cnt = 0;
  public static void main(String args[]) throws InterruptedException, ExecutionException {
      Thread t1 = new Thread(new Runnable() {
          @Override
          public void run() {
              System.out.println("Running tasks");
            while (condition)                             {
                  // **** Some IO operation that take forever ****                
                  System.out.println("iteration " + cnt++);
                  if (Thread.currentThread().isInterrupted()) {
                      System.out.println("Breaking loop");
                      return;
                  }   
              }           
          }
      });
      t1.start();
      TimeUnit.SECONDS.sleep(5);
      t1.interrupt();
      System.out.println("thread destroyed..");
  
    }
  }
  </code></pre>
  
  <p>Problem is i have added <code>interrupt</code> call but it never finishes IO call, so can i kill thread in such case</p>