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

java.lang.Thread.sleep(millis) sleeps less than specified.

XMLWordPrintable

    • x86
    • windows_nt



      Name: akC45999 Date: 05/28/98




      On win32 version of jdk1.2beta4G,
      the sleep(millis) method can sleep less time than the parameter specified.

      Such behaviour contradicts the specification.
       
      ------------------------------------- file sleep0101.java
      //File: @(#)sleep0101.java 1.2 97/12/08
      //Copyright 12/08/97 Sun Microsystems, Inc. All Rights Reserved

      //package javasoft.sqe.tests.api.java.lang.Thread.sleep0101;

      import java.io.PrintStream;
      //import javasoft.sqe.harness.Status;
      //import javasoft.sqe.harness.Test;

      class Status {
        public static int failed(String msg) {
      System.out.println("Failed. "+msg);
      return 97;
        }

        public static int passed(String msg) {
      System.out.println("Passed. "+msg);
      return 97;
        }
      }
      public class sleep0101 {// implements Test {

        public int run(String argv[], PrintStream log, PrintStream out) {
              Thread me=Thread.currentThread();
              int[] data={3162,1000,316,100,32,10,3,1,0};
              for (int k=0; k<data.length; k++) {
                      int delay=data[k];
                      long time=System.currentTimeMillis();
                      try {
                              me.sleep(delay);
                      } catch (Throwable e) {
                              return Status.failed("Unexpected exception in sleep("+delay+"): "+e.toString());
                      }
                      long realDelay=System.currentTimeMillis()-time;
                      if (realDelay<delay)
                              return Status.failed("sleep("+delay+") actually sleeped "+realDelay+" msec");
              }
          return Status.passed("");
        }

        public static void main(String args[]) {
      // (new sleep0101()).run(args, System.err, System.out).exit();
           System.exit((new sleep0101()).run(args, System.err, System.out));
        }

      }
      ------------------------------------- end of file sleep0101.java

      Intermittenly, it failed with results:
      Failed. sleep(316) actually sleeped 312 msec
      Failed. sleep(32) actually sleeped 31 msec

      ======================================================================

            hongzh Hong Zhang
            rfqsunw Rfq Rfq (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: