title: How to pause running thread and restart same thread when needed?
body: <p>i want to pause thread which is writing messages in file by iterate message list. When message list is empty i want thread to stop and thread is resumed when message in a list.</p>
  
  <p>I know stop,suspend (),resume methods is deprecated but if thread is continuously in background it consumes cpu. I did lots of googling but can't find proper answer. please any one help me out </p>
  
  <p>Here is my code: </p>
  
  <pre class="lang-java prettyprint-override"><code> private Thread mFileWriterThread = new Thread() {
  
      @Override
      public synchronized void run()         {
          while (mIsRunning) {
              synchronized (mMessageList) {
                  Iterator it = mMessageList.iterator();
                  while ((it.hasNext())) {
                      String message = (String) it.next();
                      writeToFile(fileOutputStream, message);
                      mMessageList.remove(message);
  
                  }
              }
          }
      }
  
  };
  </code></pre>