8 Replies Latest reply: Feb 9, 2009 7:38 AM by masijade RSS

    Difference between thread.sleep and BufferedReader.readline()

    807588
      Hi All,

      I have J2SE application which is infact a listener, to keep it working for 24/7 what you people suggest do i use

      while(true)
      {
      Thread.sleep(10000);
      }

      or


      BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
      System.out.print("Enter Quit to Exit.. ");
      String cmd = br.readLine().trim();
      if (cmd.equalsIgnoreCase("quit"))
      {
      System.out.println("Quitting...");
      System.exit(0);
      }

      Please also suggest which one is optimized solution.

      Regards,
      raza