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

Thread.sleep(3) might wake up immediately on windows

    Details

    • Subcomponent:
    • Resolved In Build:
      b13
    • CPU:
      x86
    • OS:
      windows_2000, windows_2003

      Description

      This program:
      ---------------------------------------------------
      public class uu {
          public static void main(String[] args) throws Throwable {
      long t0 = System.currentTimeMillis();
      java.util.concurrent.TimeUnit.MILLISECONDS.sleep(3);
      System.out.println(System.currentTimeMillis()-t0);
          }
      }
      ---------------------------------------------------
      should print a number no less than 3, but on windows-amd64
      and more rarely, windows-i586, it often prints 0.
      Probably a hotspot bug (but it could conceivably be core libraries)

      This causes j2se regtest test/java/util/concurrent/TimeUnit/Basic.java to fail
      Doug Lea asked,

      What happens if you instead just call Thread.sleep(3)?

      Good question.

      -----------------------------------------------------
      public class uu {
          public static void main(String[] args) throws Throwable {
      if (args.length == 1 && args[0].equals("TimeUnit")) {
      long t0 = System.currentTimeMillis();
      java.util.concurrent.TimeUnit.MILLISECONDS.sleep(3);
      System.out.println(System.currentTimeMillis()-t0);
      } else if (args.length == 1 && args[0].equals("Thread")) {
      long t0 = System.currentTimeMillis();
      Thread.sleep(3);
      System.out.println(System.currentTimeMillis()-t0);
      }
          }
      }
      -----------------------------------------------------
      The above program, when invoked with either argument "Thread" or "TimeUnit"
      prints "0" on windows-amd64 most of the time.
      So this is definitely not a TimeUnit bug.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dholmes David Holmes
                Reporter:
                martin Martin Buchholz
              • Votes:
                0 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: