title: is there an option to cancel a task in ScheduledExecutorService?
body: <p>I am writing an application on javaFX and as a part of my view(in MVVM architecture) I am using an FXML Label for the status of my application to present for the client(for example: if a file was uploaded successfully or not).</p>
  <p>I want to clean this status label a few seconds after an update was made.</p>
  <p>I used this code to run a thread to do so but the problem occurs when more than one update was made before the previous finished its job.</p>
  <p>I thought of canceling any previous threads in the thread-pool before executing a new thread but I didn't find a way to do so.</p>
  <pre><code>public class MainWindowController implements Observer {
  
      ViewModel vm;
      ScheduledExecutorService scheduledExecutorService;
      Stage stage;
      @FXML
      Label appStatus;
  
      public void loadProperties(){
          FileChooser fc = new FileChooser();
          fc.setTitle(&quot;Load Project Properties&quot;);
          fc.setInitialDirectory(new File(&quot;./resources&quot;));
          FileChooser.ExtensionFilter extensionFilter = new FileChooser.ExtensionFilter(
                  &quot;XML Files (*.xml)&quot;, &quot;*.xml&quot;);
          fc.getExtensionFilters().add(extensionFilter);
          File chosenFile = fc.showOpenDialog(stage);
  
          //CONTINUE HERE
          if(chosenFile==null){
              appStatus.setTextFill(Color.RED);
              vm.appStat.setValue(&quot;Failed to load resource&quot;);
          }
          else{
              vm.setAppProperties(chosenFile.getAbsolutePath());
          }
          cleanStatusBox();
  
      }
  
      public void cleanStatusBox(){
          scheduledExecutorService.schedule(new Runnable() {
              @Override
              public void run() {
                  Platform.runLater(()-&gt;vm.appStat.setValue(&quot;&quot;));
              }
          },10000, TimeUnit.MILLISECONDS);
      }
  
      public void setViewModel(ViewModel vm) {
          this.vm = vm;
          scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
          appStatus.textProperty().bind(vm.appStat);
      }
  }
  </code></pre>