Thread.sleep() takes too long

XMLWordPrintable

    • Type: Bug
    • Resolution: Not an Issue
    • Priority: P4
    • None
    • Affects Version/s: 6u31
    • Component/s: core-libs

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
      Java(TM) SE Runtime Environment (build 1.7.0_05-b05)



      ADDITIONAL OS VERSION INFORMATION :
      Debian GNU/Linux 6.0.5 (squeeze)

      A DESCRIPTION OF THE PROBLEM :
      Thread.sleep() takes few times too much time than should!

      Problem occures in jre 6 and jre 7.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just run this simple code:

          try {
            System.out.println("start");
            long t = new Date().getTime();
            Thread.sleep(500);
            System.out.println("took: "+(new Date().getTime() - t)+" ms.");
          } catch (Exception x ) {
            x.printStackTrace();
          }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      output should be:

      start
      took: 500 ms


      ACTUAL -
      always different:

      start
      took: 49085 ms.

      start
      took: 19406 ms.

      etc

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      no errors

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.Date;


      public class TimeOutTest {

        public static void main(String[] args) {
          
          try {
            System.out.println("start");
            long t = new Date().getTime();
            Thread.sleep(500);
            System.out.println("took: "+(new Date().getTime() - t)+" ms.");
          } catch (Exception x ) {
            x.printStackTrace();
          }
          
        }
      }

      ---------- END SOURCE ----------

      SUPPORT :
      YES

            Assignee:
            Unassigned
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: