title: Java Loop with sleep
body: <p>To fulfill the needs of my company I need to implement a loop which </p>
  
  <ol>
  <li>reads records which have a field equal to a flag, </li>
  <li>either sleeps (if the result is empty) or performs tasks outlined by the data in the records</li>
  <li>update statuses</li>
  <li>and repeats 1.</li>
  </ol>
  
  <p>The user of the loop should be able to to switch of the loop by setting a flag from outside the loop.</p>
  
  <p>I have tried implementing it using a <code>while</code> loop with <code>sleep</code> but I would like to know if there are better alternatives.</p>