title: How to make a while to run until scanner get input?
body: <p>I'm trying to write a loop which runs until I type a specific text in console where the application is running. Something like:</p>
  
  <pre><code>while (true) {
  try {
      System.out.println("Waiting for input...");
      Thread.currentThread();
      Thread.sleep(2000);
      if (input_is_equal_to_STOP){ // if user type STOP in terminal
          break;
      }
  } catch (InterruptedException ie) {
      // If this thread was intrrupted by nother thread
  }}
  </code></pre>
  
  <p>And I want it to write a line each time it pass through so I do not want it to stop within the while and wait for next input. Do I need to use multiple threads for this?</p>