title: how to close a user defined Thread with close (X) icon of the scren in JavaFX?
body: <p>I use the following code to create a user-defined Java Thread and perform some action continuously. then I want to destroy this Thread while the user wants to close the windows and clicks on (X) icon of the window. </p>
  
  <pre><code>class Simple
  {   
      Threa thread;
      @Override
      public void initialize(URL url, ResourceBundle rb) {    
          thread = new Thread(new MyThreadClass(this));
          thread.start();
      }
  //code
  }//Simple
  
  class MedicalStoreSalesPageControllerThread implements Runnable {
      @Override
      public void run() {
          //Action which is continuously performed
      }
  }//MedicalStoreSalesPageControllerThread
  </code></pre>
  
  <p>I'm talking about (X) sign at top right corner of window</p>
  
  <p><a href="https://i.stack.imgur.com/HD43d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HD43d.png" alt="I&#39;m talking about (X) sign at top right corner of window"></a></p>