title: Thread.sleep(); in Java
body: <p>Whenever I use Thread.sleep(); in a do while loop, the hints tell me, "Invoking Thread.sleep in loop can cause performance problems." I have heard this from many other websites and books. What is something I can use instead?</p>
  
  <p>Here's the code:</p>
  
  <pre><code>import javax.swing.*;
  
  public class Delay {
  
      public static void main(String[] args) throws Exception {
          int difficulty;
          difficulty = Integer.parseInt(JOptionPane
                  .showInputDialog("How good are you?\n" + "1 = evil genius...\n"
                          + "10 = evil, but not a genius"));
          boolean cont;
          do {
              cont = false;
              System.out.println("12");
              Thread.sleep(500);
  
              String again = JOptionPane.showInputDialog("Play Again?");
              if (again.equals("yes"))
                  cont = true;
          } while (cont);
      }
  }
  </code></pre>