title: java: why waiting some time is making my program not execute sequentially?
body: <p>I have a GUI that displays a certain iterating process step by step.
  I want it to make one step, display the step, wait 1s, and repeat, ...</p>
  
  <p>The code:</p>
  
  <pre><code>while (! finished()) {
      advance(); // make and display one step
      try {
          Thread.sleep(1000);
      }
      catch (InterruptedException e) {       
      }
  }
  </code></pre>
  
  <p>What happens, though, is that nothing is printed until the whole added time of all sleep calls pass, and then all the steps are printed at once.
  How can I make the execution flow sequentially?</p>
  
  <p>Note: I tried replacing the sleep call with a very long, useless loop and the behaviour was the same.</p>