title: Java: Thread.sleep() inside while loop not working
body: <p>Alright, I'm new to threading, so my question might be pretty dumb. But what I want to ask is, I have this class, let's say its name is MyClass.java. And then inside one of its methods is callThread(), which I want to print something out, sleep, and return control to MyClass.java's method. How do I do that?</p>
  
  <p>Currently, my code goes something like this:</p>
  
  <pre><code>class MyClass {
      void method()
      {
          MyThread thread = new MyThread();
          thread.run();
          // do some other stuff here...
      }
  }
  </code></pre>
  
  <p>And then, this will be the MyThread:</p>
  
  <pre><code>class MyThread implements Runnable {
      public void run()
      {
          while (true)
          {
              System.out.println("hi");
              this.sleep(1000);
          }
      }
  }
  </code></pre>
  
  <p>I was hoping that MyThread would print "hi", pass back control to MyClass, and then print "hi" again one second later. Instead, MyThread freezes up my entire program so having it in there doesn't work at all...</p>
  
  <p>Is there any way around this?</p>