title: Accurate timing in java
body: <p>How can I achieve accurate timing in Java? I know Thread.sleep() is inaccurate and leads to InterruptedExceptions. I'm trying to make a physics simulator and I want to have accurate code.
  Here is my code so far:</p>
  
  <pre><code>public class FreeFall() {
      public static void main(String[] args) {
          double height = Double.parseDouble(args[0]);
          double xi = height;
          int counter = 0;
          while (true) {
              height = xi + 9.8 / * counter * counter;
              System.out.println(height);
              counter++;
              Thread.sleep(1000);
          }
      }
  }
  </code></pre>