title: How to fix Sonar issue "Remove this call to "wait" or move it into a "while" loop"?
body: <p>I am received a request to fix sonar issues in a legacy project, there is a code segment like this, every call to this function will be paused for 50ms:</p>
  
  <pre><code>synchronized(monitor) {
  
    [...]
  
    try {
  
      [...]
  
      Thread.sleep(config.getWaitTime()); // return 50
    } catch (SomeException e) {
      log.error(e.getMessage(), e);
    }
  
    [...]
  }
  </code></pre>
  
  <p>First, sonar asked me to change <code>Thread.sleep()</code> to <code>wait()</code> so I change the try block to to:</p>
  
  <pre><code>try {
  
    [..]
  
    monitor.wait(config.getWaitTime());
  } catch (SomeException e) {
    log.error(e.getMessage(), e);
  }
  </code></pre>
  
  <p>Then, another issue appear : <code>Remove this call to "wait" or move it into a "while" loop</code> , I do not have much experience with multithreading, so I'm not sure my fix is correct:</p>
  
  <pre><code>boolean wait = true;
  while (wait) {
    wait = false;
    monitor.wait(config.getWaitTime());
  }
  </code></pre>
  
  <p>Is the above solution correct? If not, what should I do?</p>