Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8340830

IO.readln and IO.println are mutually blocking

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 23
    • core-libs
    • None

      Following example demonstrates how IO::readln and IO::println are mutually blocking and how IO.println behaved differently than System.out.println in multithreaded code.


      ```
      static void doSomething() {
          try {
             Thread.sleep(1000);
         } catch (InterruptedException ignore) {}
      }
       
      void main() {
         Thread.ofVirtual().start(() -> {
              while (true) {
                  doSomething();
                 System.out.println("I do something until you press Enter");
             }
         });
         Thread.ofVirtual().start(() -> {
              while (true) {
                  doSomething();
                  println("I'm blocked until you press Enter");
             }
         });
          readln("");
      }
      ```

            naoto Naoto Sato
            asotona Adam Sotona
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: