title: Java while loop with certain time
body: <p>I use a consumer to take items from a queue and send the items to an external API</p>
  
  <pre><code>public void run(){
      try {
          while(true){
               //will peek() an item from a queue and send it to an external API
               sendRequest(item);
               thread.sleep(100);
          }
      } catch(InterruptedException e){
          Thread.currentThread().interrupt();
      }
  }
  </code></pre>
  
  <p>And have another method to send the request </p>
  
  <pre><code>public void sendRequest(JSONibject item){
       // send request
  
      if(response.getStatus() == 200){
          //will remove the item from the queue
      }
      if(response.getStatus() == 500){
          //keep the item in the queue and set time for resending
      }
  }
  </code></pre>
  
  <p>So what I want to do is when I get the 500 response which means the server is not up. I will keep the items in the queue and try to resend the items every 5 mins. How can I control the while loop in that situation?</p>