title: How can I interrupt and resume a thread without the use of deprecated methods?
body: <p>I am trying to get into threading and did some research on how to pause/stop/resume threads, but due to the .stop , .resume etc. methods being deprecated I currently don't really know how to do it.</p>
  
  <p>I found .Interrupt, but couldn't get any useful information on how to resume it after interrupting it.</p>
  
  <p>So far I am working with a workaround I came up myself, which would consist of adding a state variable to it, and checking for the state each iteration. But I don't think that is a good solution, it may be working in a small scale code, but it's no option for big codes.</p>
  
  <p>This would be my code right now:</p>
  
  <pre><code>public class sleep implements Runnable
  {     
  private int wakeup=0;
  public void setwakeup(int wakeupstate)
  {
      wakeup=wakeupstate;
  }
  
  public void run()
  {       
  
    while(wakeup==0)
    {
      //Code to be done in every Iteration
    }
  
   }
  
  }
  </code></pre>
  
  <p>I would use the setwakeup method in order to control the thread, but it would still be running from the moment on I start it.</p>
  
  <p>Is there no way to pause and resume it? As I said, I only found the .Interrupted method and I don't think that's the way to go, I'm very unsure what happens if the thread is being interrupted while working on the code in the loop. My guess would be that it would be throwing a lot of exceptions.</p>
  
  <p>So, how can I safely pause and resume a thread?</p>