title: progress bar containing thread is not running for the second time in javafx
body: <p>I have a progress bar which in my application which runs properly for the first time.The progress bar runs based on the size of the observableArrayList. When I change the size of the observableArrayList and run it again or return to the page from a different page, it doesnt work properly. I am able to get only the text and the indeterminate progress bar in the page. The process count and the elapsed time are not getting displayed. I 've put the logic of this inside a Task. When I put the log lines at specific places I find that sometimes it doesnt enter certain places like Platform.runlater(new Runnable) inside the task's call method. Please find the code below. I am using scenebuilder for the UI part.</p>
  
  <pre><code>public class ProgressBarController implements Initializable {
  
  public static final Stage stage ;
  @FXML
  ProgressBar progressBar;
  @FXML
  public static Button cancelButton;
  @FXML
  Button save;
  @FXML
  Label totalprocess;
  @FXML
  Label runningprocess;
  
  
  
  /**
   * Initializes the controller class.
   */
  @Override
  public void initialize(URL url, ResourceBundle rb) {
  
      final Task task;
      task = new Task&lt;Void&gt;() {
          @Override
          protected Void call() throws Exception {
  
              for (int i = 0; i &lt; rightObservableArrayList.size(); i++) {
  
                  final int k = i + 1;
                  //setting the value for total number of processes
                  totalprocess.setText("total number of process");
                  //setting the value for the current process. It gets updated as the loop increments.
                  Platform.runLater(new Runnable() {
                      @Override
                      public void run() {
                          runningprocess.setText(Integer.toString(k));
                      }
                  });
  
                  /*
                    some processing for the current val 
                  */
  
                  //update the progressBar
                  updateProgress(i + 1, &lt;totalprocesssize&gt;);
                  updateMessage(String.valueOf(i));
                  Platform.runLater(new Runnable() {
                      @Override
                      public void run() {
                          /*
                           some code to display the total time to run the process
                          */
                      }
                  });
              }
              return null;
          }
      };
      progressBar.progressProperty().bind(task.progressProperty());
      Label labelCount = new Label();
      labelCount.textProperty().bind(task.messageProperty());
      new Thread(task).start();
      task.setOnSucceeded(new EventHandler&lt;WorkerStateEvent&gt;() {
          @Override
          public void handle(WorkerStateEvent t) {
  
                ///some code
              }
          }
      });
  }
  @FXML
      public void cancelFired(ActionEvent event) throws IOException {
          cancelFlag = true;
          progress.setScene(cancelButton.getScene());
          progress.close();
      }
  </code></pre>
  
  <p>Any ideas about why this happens will be really helpful. Kindly share your thoughts.</p>