title: Stop main thread until all events on JavaFX event queue have been executed
body: <p>While debugging an application I would like the main thread to wait after each Runnable I put on the JavaFX event queue using </p>
  
  <pre><code>Platform.runLater(new Runnable()... )
  </code></pre>
  
  <p>to wait until it has been executed (i.e. is visible). However there are two twists here:</p>
  
  <p>First, it is not really a standard, GUI driven JavaFX app. It is rather a script showing and updating a JavaFX stage every now an then. So the structure looks something like this:</p>
  
  <pre><code>public static void main(String [] args){
      //do some calculations
      SomeView someView = new SomeView(data); //SomeView is basically a wrapper for  a stage
      PlotUtils.plotView(someView) //displays SomeView (i.e. the stage)
      //do some more calculations
      someView.updateView(updatedData)
      //do some more calculations
  }
  
  public class SomeView {
      private static boolean viewUpdated = false;
      private ObservableList&lt;....&gt; observableData;
      public void updateView(Data data){
          Platform.runLater(new Runnable() {
              @Override
              public void run() {
                  observableData.addAll(data);
                  boolean viewUpdated = true; 
              }
          });
      //If configured (e.g using boolean switch), wait here until
      //the Runnable has been executed and the Stage has been updated.
      //At the moment I am doing this by waiting until viewUpdated has been
      //set to true ... but I am looking for a better solution!
      }
  }
  </code></pre>
  
  <p>Second, it should be easy to disable this "feature", i.e. to wait for the Runnable to be executed (this would be no problem using the current approach but should be possible with the alternative approach as well).</p>
  
  <p>What is the best way to do this? </p>
  
  <p>E.g. is there something like a blocking version to execute a Runnable on the JavaFX thread or is there an easy way to check whether all events on the event queue have been executed/ the eventqueue is empty....?</p>