title: Most efficient way to terminate a Thread if an FX thread is terminated in Java
body: <p>I've written a simple JavaFX application that is obviously running on FX application thread. The application needs some background processing in an infinite loop running on a separate thread(not FX thread) where I call <strong><em>Platform.runLater()</em></strong> to update the gui controls of the FX application after a fixed interval.
  If I close the FX Gui Application, the background thread continues it execution.</p>
  
  <p>In order to terminate the background thread after FX thread has terminated, I am now using <strong><em>fxThread.isAlive()</em></strong> in the while loop on the background thread. 
  This way, the background thread automatically terminates as soon as the FX Thread is terminated as the while loop condition becomes false.</p>
  
  <p>Is this a bad choice? What are the alternative and efficient ways to accomplish the same task? </p>
  
  <pre><code>//imports
  public class SimpleClockFX implements Application{  
  Thread fxThread;  
   //other variables  
  
  @Override  
  public void start(Stage primaryStage){  
      fxThread = Thread.currentThread();  
  
      //other stuff...  
  
      new Thread(()-&gt;{  
      //logic...  
        while(fxThread.isAlive()){  
            //logic...  
                    Platform.runLater(()-&gt;{
                        //update gui controls
                    });
        }  
      }).start();  
  </code></pre>
  
  <p>}</p>