title: Will an infinite 'while loop' consume excessive resources
body: <p>I want to trigger a Java code at specific timing, let say every morning 1 AM.</p>
  
  <p>I write a thread as below:</p>
  
  <pre><code>while (true) {
      if (currentTime = 1AM) {
          doSomething;
      }       
  }
  </code></pre>
  
  <p>I am a bit worry, the <strong><code>while loop</code></strong> keep running, will it slow down the machine, or eating up processing resource?</p>
  
  <p>My first question is, I am thinking if I only loop 1 time per second, will it better?</p>
  
  <pre><code>while (true) {
      if (currentTime = 1AM) {
          doSomething;
      }       
  
      Thread.sleep(1000);
  }
  </code></pre>
  
  <p>My second question is, some time I see <strong><code>while loop</code></strong> written as below, most of time to acquire the Java lock, can anyone explain how expensive if we write the <strong><code>while loop</code></strong> like below (sorry if this is very basic question)?</p>
  
  <pre><code>while (isLock) {
      // do nothing
  }
  
  doThisIfNoLock();
  </code></pre>
  
  <p>I extend the thought above, if I create a empty thread, and an infinite empty <strong><code>while loop</code></strong> inside, how many resource (processing power) that actually eating up by the thread? Because there is no content inside the loop, based on my imagination, the loop will be running very fast, and end up taking many cycles of CPU power? Is that true?</p>