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

Java Thread.sleep(timeout) is influenced by changes to System time on Linux

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 5.0u3
    • Fix Version/s: 6
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b53
    • CPU:
      sparc
    • OS:
      linux_redhat_9.0

      Description

      Thread.sleep(timeout) is influenced by changes to System time on *_Linux_*.
         
          Tested both on:

              Red Hat Linux release 9 (Shrike)

              Kernel 2.4.20-8 on an i686

          and

             Red Hat Enterprise Linux ES release 3 (Taroon Update 4)



          The test is simple,

          call Thread.sleep(15000) and change the time two hours back

          i.e. start at 13:00 call thread.sleep and at 13:05 change the time to 11:05

          you will notice that the sleep does not return at 11:15, not even when the time

          is then fixed back to 13:15


              The test case is simple,

              System.out.println("Press key before sleeping for 15 seconds...");
              System.in.read();
              Thread.sleep(15000);
              System.out.println("Woke-up.");

              ---
              e.g.
                run the test, Press <Enter> at 11:34:00 (00 seconds)
                At 11:34:05 change the clock to 09:34:05 (two hours back)
                Expected result: at 09:34:15 the thread will wake up.

                If the same test is conducted on Windows machine then it works.
                If the clock is set to a _future _time, the test works also for linux.

                I have tested this with the following JDKs:
                1. Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
                   Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode, sharing)
                              [ FAILED ]
                2. Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
                   Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
                              [ FAILED ]
                3. Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_07-b05)
                   Java HotSpot(TM) Client VM (build 1.4.2_07-b05, mixed mode)
                              [ PASSED ]
              ---
              Please note that this same test _*PASSED*_ on build 1.4.2_07-b05.

              Please find attached are the following:
              Tester.java - test case
              specification.txt - machine specification
              threadDump.txt - thread dump while thread.sleep didn't wake up

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              hhuangsunw Hui Huang (Inactive)
              Reporter:
              duke J. Duke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: