title: Why does this code wait 1000ms instead of 500ms?
body: <p>I don't understand how this code prints 1000 instead of 500. Is there something I am missing?</p>
  <pre><code>    PipedOutputStream writer = new PipedOutputStream();
      PipedInputStream reader = new PipedInputStream();
      writer.connect(reader);
      BufferedReader stream = new BufferedReader(new InputStreamReader(reader));
  
      ScheduledExecutorService thread = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().build());
      thread.schedule(() -&gt; {
          try {
              Thread.sleep(500);
              writer.write(&quot;test\n&quot;.getBytes(StandardCharsets.UTF_8));
          } catch (InterruptedException | IOException ignored) {
          }
      }, 0, TimeUnit.MILLISECONDS);
  
      long startTime = System.currentTimeMillis();
      stream.readLine();
      long duration = System.currentTimeMillis() - startTime;
      System.out.println(duration);
  </code></pre>