title: Replacing busy loop and sleep in thread
body: <p>I have a Thread that calls a certain service.
  The service defines a callback function that can be called multiple times
  as long as there is data onProcessing().</p>
  
  <p>The onCompletion() is called once it is finished.</p>
  
  <pre><code>public CallThread implements Runnable{
      public boolean isCompleted = false;
      public void run(){
          ResponseObserver response = new ResponseObserver(){ 
              public void onException(){
                  //Errors could happen sometimes so the program should just issue another request
              }
              public void onCompletion(){
                  isCompleted = true;
                  //process the result
              }
              public void onProcessing(){
                  //This could be called multiple time
              }
          }
  
              //Service is the object that calls the service
          Service service = getService();
  
          while(!isCompleted){
              //Request object is populated
              Request request = supplyRequest();
  
              service.getDetails(request, response);
  
              //How to remove this sleep
              Thread.sleep(10 * 1000);
          }
      }
  }
  </code></pre>
  
  <p>I have created a busy loop that checks for the isCompleted and having it sleep.
  What I am doing now..is to use sleep command to be able for the function to be completed
  until issuing a next request.</p>
  
  <p>I am not sure if this is optimal as sometimes..it does not take 10 seconds before
  onCompletion() is called.
  I just wanted the service to return something before I could issue another request.</p>
  
  <p>Is there a way to optimized my code?</p>