title: How to pause thread in java?
body: <p>So what's the best way to pause a thread? So far I have something like this: In main loop of the thread, first line is:</p>
  
  <pre><code>while (paused == true) {
     Thread.sleep(refreshRate);
  }
  </code></pre>
  
  <p>And it works perfercly. I can change paused state pressing P key. But Im looking for better, more professional solution. I know about reentrant locks and conditions. So I could use them on the thread. And then presing P would release singalAll() method. But it would slow my app a lot because of synchronization which I don't really need in this thread. So what is the best, most perform way to solve it? Maybe using synchronization blocks?</p>
  
  <pre><code>synchronized (new Object()) {
  
  }
  </code></pre>
  
  <p>Then just part of code would be synchronized. Or maybe I should use semaphores?</p>