title: JavaFX freezes GUI when doing a scheduled long calculation
body: <p>I am making a desktop application that will sync computer's file with the database. It is scheduled every 5 seconds to check whether there is an internet connection
  I am using TimeLine for schedule and Service (Task) for repeating this task: </p>
  
  <p>My schedule: </p>
  
  <pre><code>public void sync() {
      SyncTask syncTask = new SyncTask(bar);
      Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(5), 
          e -&gt; {
              if (needSync() &amp;&amp; syncTask.isDone()) {
                  syncTask.bind();
                  syncTask.start(); 
              }
      }));
      timeline.setCycleCount(Animation.INDEFINITE);
      timeline.play();
  }
  </code></pre>
  
  <p>My SyncTask class: </p>
  
  <pre><code>private class SyncTask {
      private ProgressBar bar;
      public SyncTask(ProgressBar bar) {
          this.bar = bar;
      }
      Service&lt;Boolean&gt; service = new Service&lt;Boolean&gt;() {
          @Override
          protected Task&lt;Boolean&gt; createTask() {
              return new Task&lt;Boolean&gt;() {
                  @Override
                  public Boolean call() {
                      return syncSomethingHere();
                  }
              };
          }
      };
  
      public void bind() {
          bar.progressProperty().bind(service.progressProperty());
          bar.setVisible(true);
          service.setOnSucceeded(ev -&gt; {
              bar.setVisible(false);
          });
      }
  
      public void start() {
          service.restart();
      }
  
      public boolean isDone() {
          return !service.isRunning();
      }
  
  }
  </code></pre>
  
  <p>But it starts freezing my GUI whenever it needs to update. 
  Is there any way that I can avoid it ? 
  Thanks in advance.</p>