Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2046977 | 1.4.1 | Yumin Qi | P4 | Closed | Fixed | hopper |
JDK-2046976 | 1.4.0_02 | Yumin Qi | P4 | Closed | Fixed | 02 |
The 5 ms sleep causes a call to NTSetTimerResolution in the OS to set the timer to 1 ms resolution (in order to discriminate the passage of 5 ms).
The multithreading of the timers is causing a problem.
The problem is not observed in classic mode, or using the MS virtual machine.
TESTCASEBEGIN
/**
* This class is meant to demonstrate an issue with the system time when
running the HotSpot VM and sleeping for less than 10 ms. When it is run with the HotSpot VM, the system time will be off. The program will run for 10 system minutes, but when verifying with a stop watch, is took only 9 minutes and 50 seconds.
* Steps to try this:
* 1. Set a count-down timer to 10 minutes.
* 2. At the same moment, run the application and start the count-down timer.
* 3. At the moment the software stops, stop the timer. When the timer is
zero,it means that the system took 10 real minutes. When there is time left on the timer, the system took less than 10 minutes.
+ * Another way to try this:
+ * 1. Remove the code where the "timer" is created so the application
+ * will not stop after 10 minutes.
+ * 2. Set an external clock at exactly the same time as the computer clock.
+ * 3. Run the application.
+ * 4. After a couple of hours, compare the system clock with the external
clock.
+ Note that the system clock is a couple of minutes fast.
*/
public class TestBase {
public int launchThread(final int id, final int sleepTime) {
// Create a new thread object
Thread t = new Thread(new Runnable() {
public void run() {
// Loop forever
while (true) {
// Print the ID
System.out.print(""+id);
// Do some processing
for (int i=0; i<1000; i++) {
for (int j=0; j<1000; j++) {
double x = (double)i * j / j + i - j * j;
}
}
// Sleep for the amount specified in the sleep time
try {
Thread.currentThread().sleep(sleepTime);
}
catch (InterruptedException e) {
;
}
}
}
});
// Start the thread
t.start();
return 0;
}
public static void main(String[] args) {
// Create a Thread that will print the ms time every 30 seconds
Thread timer = new Thread(new Runnable() {
public void run() {
// Print the begin time
long start = System.currentTimeMillis();
System.out.println("Start time: " + start);
try {
// Sleep for 10 minutes
Thread.currentThread().sleep(600000);
}
catch (InterruptedException e) {
;
}
// Print the current time
System.out.println("time: " +(System.currentTimeMillis() - start));
System.exit(0);
}
});
// Start the timer thread
// Remove this line of code when it is not desired to stop the app after 10 minutes.
timer.start();
// Create a new test base object
TestBase tb = new TestBase();
// Launch a thread with a 5 ms sleep time
tb.launchThread(1, 5);
// Launch a thread with a 10 ms sleep time
tb.launchThread(2, 10);
}
}
TESTCASEEND
- backported by
-
JDK-2046976 Calling Thread.sleep with small argument affects system clock on windows
-
- Closed
-
-
JDK-2046977 Calling Thread.sleep with small argument affects system clock on windows
-
- Closed
-
- duplicates
-
JDK-4881604 When calling newAudioClip(), the PC's clock will progress 1 second in 1 hour
-
- Closed
-
-
JDK-4814012 System clock acceleration on Windows still exists
-
- Closed
-
- relates to
-
JDK-6435126 ForceTimeHighResolution switch doesn't operate as intended
-
- Closed
-
-
JDK-4717583 High resolution Thread.sleep() needs lower overhead on Windohs
-
- Closed
-
-
JDK-4712392 REGRESSION: Reduced default resolution for Thread.sleep() breaks apps.
-
- Closed
-
-
JDK-5005837 rework win32 timebeginperiod usage
-
- Closed
-