title: How to stop waiting for line from System.in?
body: <p>I have a service which performs a reading from standard input. Here it is</p>
  
  <pre><code>public class ReaderService{
      private BufferedReader reader;
      private volatile boolean closed;
  
      public void start(){
          while(!closed){
              reader = new BufferedReader(new InputStreamReader(System.in));
              try {
                  System.out.println(reader.readLine());
              } catch (IOException e) {
                  System.out.println("IOException");
              }
          }
      }
  
      public void stop(){
          try {
              reader.close();
          } catch (IOException e) {
              System.exit(1);
          }
          closed = true;
      }
  }
  </code></pre>
  
  <p>I use it as follows:</p>
  
  <pre><code>public static void main(String[] args) throws InterruptedException{
      Thread t = new Thread(new Runnable() {
          public void run() {
              reader.start();
          }
      });
      t.start();
      Thread.sleep(5000);
      reader.stop();
  }
  </code></pre>
  
  <p>The issue is that calling <code>ReaderService::stop()</code> does not interrupt wainting for the next line. I thought it would throw <code>IOExecption</code>. </p>
  
  <p>Is there a way to "interrupt" such a service from another thread? Maybe <code>BufferedReader</code> is not quite a good choice here...</p>