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

Thread.sleep() always seems to have about 10millisecs more than the actual sleep

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.4

      Description


      Here is the code and its output. The timings on the right side of the output need to be
      divided by 100 to get the timing for each thread.sleep() call. The output reflects the result
      of running the sleep() call 100 times. The bug only occurs on Solaris. WinNT/95 works fine.

      ___________________
      import java.applet.*;
      import java.awt.*;

      public class sleepbug extends Applet {
          int delay = 40;
          public void init() {
      delay = Integer.parseInt(getParameter("sleep"));
          }
          public boolean mouseDown(Event evt, int x, int y) {
      long s, e;
      s = System.currentTimeMillis();
      for (int i=0; i<100; i++) {
      try {
      Thread.currentThread().sleep(delay);
      } catch (Exception exc) {
      }
      }
      e = System.currentTimeMillis() - s;
      System.out.println("sleep("+delay+") = "+e);
      delay += 10;
      return true;
          }
      }
      ----------------------

      Output:
      ======
      [120][wspace] ? appletviewer sleepbug.html
      status: applet loaded
      status: applet initialized
      status: applet started
      sleep(40) = 4857
      sleep(50) = 5954
      sleep(60) = 6833
      ...

        Attachments

          Activity

            People

            Assignee:
            never Tom Rodriguez
            Reporter:
            vssriniv Vijay Srinivasan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: