title: Cancel BufferedReader's readLine()
body: <p>I've written an endless loop in which I want to send a User Message every 5 seconds. Therefore I wrote a thread which waits for 5 seconds and then sends the Message received by the readLine() Method. If the user doesn't give any input the loop doesn't go on because of the readLine() Method waiting for input. So how can I cancel the readLine() Method?</p>
  
  <pre><code>while (true) {
          new Thread() {
              @Override
              public void run() {
                  try {
                      long startTime = System.currentTimeMillis();
                      while ((System.currentTimeMillis() - startTime) &lt; 5000) {
                      }
                      toClient.println(serverMessage);
                      clientMessage = fromClient.readLine();
  
                      System.out.println(clientName + ": " + clientMessage);
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          }.start();
          serverMessage = input.readLine();
      }
  </code></pre>