title: Java - Unable to stop runnable from main class
body: <p>I am banging my heads against the desk here friends. This is what I'm trying to accomplish. I have a Main class, that will create a new thread. Right now, when the thread is done working, it will perform some minor clean, and the thread is stopped. However, I have a "Stop" button on the UI, that when pressed, should "do some cleanup, then kill the thread. The problem is, I can't seem to update anything that is inside of that new thread that I created.</p>
  
  <p>Here are some snippets:</p>
  
  <p>Main Class</p>
  
  <pre><code>runner = new Thread(new Controller1(options));
  runner.start();
  </code></pre>
  
  <p>In the Above code, I'm calling my Controller1 class, and setting some "options" in the constructor. This is working good so far...</p>
  
  <p>Now, in the Controller1 class, this is what I have...</p>
  
  <pre><code>public volatile static boolean stopped;
  
  public void run() {
      while(!stopped ){
          System.out.println("In run");
          startProxy(proxyPort);
          startWebDriver();
          driver.get(http);
          UIMainJSwing1.updateStartButton();
          stopped=true;
      }
  
      //Run killAll to stop webdriver and the proxy
      killAll();
      System.out.println("Thread complete");
  }
  </code></pre>
  
  <p>The problem is, from the Main class, I can't call or set "stopped" to true. I can call runner.interrupt(), but the problem is, since the thread just dies, my killAll() function is never ran, and I'm left with the WebDriver and Proxy still running. </p>