title: Stopping thread Immediately
body: <p>I want to stop a running thread immediately. Here is my code:</p>
  
  <p>Class A :</p>
  
  <pre><code>public class A() {
      public void methodA() {
          For (int n=0;n&lt;100;n++) {
          //Do something recursive
          }
          //Another for-loop here
  
          //A resursive method here
  
          //Another for-loop here
  
          finishingMethod();        
      }    
  }
  </code></pre>
  
  <p>Class B:</p>
  
  <pre><code>public class B() {
      public void runEverything() {
          Runnable runnable = new Runnable() {
              @Override
              public void run() {
                  try {
                      Thread.sleep(1000);
                      A a = new A();
                      a.methodA();
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
          };
         Thread thread = new Thread(runnable);
         thread.start();
      }
  </code></pre>
  
  <p>My problem is that i need to be able to stop the thread in Class B even before the thread is finished. I've tried interrupt() method, but that doesn't stop my thread. I've also heard about using shared variable as a signal to stop my thread, but I think with long recursive and for-loop in my process, shared-variable will not be effective.</p>
  
  <p>Any idea ?
  Thanks in advance.</p>